-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72983e6
commit dd7a702
Showing
10 changed files
with
310 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
namespace N27_HT1.Models; | ||
|
||
public class USer | ||
public class User | ||
{ | ||
|
||
public Guid Id { get; set; } | ||
string EmailAddress { get; set; } | ||
public string Password { get; set; } | ||
public bool IsAdmin { get; set; } | ||
|
||
public User() | ||
{ | ||
|
||
} | ||
|
||
public User(string emailAddress, string password, bool isAdmin = false) | ||
{ | ||
Id = Guid.NewGuid(); | ||
EmailAddress = emailAddress; | ||
Password = password; | ||
IsAdmin = isAdmin; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"Email: {EmailAddress}password: ******"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*User modelidan foydalaning ( id, emailAddress, password, isAdmin ) | ||
UserService dan foydalaning | ||
unda quyidagi methodlar bo'lsin | ||
- Users collection | ||
- Add ( emailAddress, password ) - user ni validate qilib qo'shadi | ||
- GetUsers - userlar kolleksiyasini qaytaradi | ||
foydalanuvchilar orasida asosan admin foydalanuvchi hamma foydalanuvchilardan oldin registratsiya bo'lgan bo'lishi kerak | ||
- UserService da Users collectionga initialize qilganda default qilib 3 ta user qo'shib qo'ying | ||
- Add methodi orqali 2 ta user qo'shing | ||
- GetUsers methodi orqali User larni olib, ekranga chiqaring | ||
PS : bunda EnsureAdminExists private methodi orqali admin borligini tekshirib userlar orasiga qo'shib qo'yish mumkin | ||
va bu methodni konstruktorda ishlatsa bo'ladi*/ | ||
|
||
using N27_HT1.Services; | ||
|
||
var userService = new UserService(); | ||
userService.Add("[email protected]","QgGuio0770Qa"); | ||
userService.Add("[email protected]","Qodir7229"); | ||
userService.GetUsers().ForEach(user => Console.WriteLine(user)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,47 @@ | ||
namespace N27_HT1.Services; | ||
using System.Text.RegularExpressions; | ||
using N27_HT1.Models; | ||
|
||
namespace N27_HT1.Services; | ||
|
||
public class UserService | ||
{ | ||
private List<User> _users; | ||
|
||
public UserService() | ||
{ | ||
_users = new List<User> | ||
{ | ||
new User("[email protected]", "eshmat747"), | ||
new User("[email protected]", "fedya2232"), | ||
new User("muminow04gmail", "muhiddinov94") | ||
}; | ||
EnsureAdminExists(_users); | ||
|
||
} | ||
|
||
public void Add(string email, string password) | ||
{ | ||
const string regexEmail = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; | ||
Regex regex = new Regex(regexEmail); | ||
if (!regex.IsMatch(email) || string.IsNullOrWhiteSpace(email)) | ||
throw new ArgumentException("Invalid email"); | ||
const string regexPassword = @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$"; | ||
Regex regexpassword = new Regex(regexPassword); | ||
if(!regexpassword.IsMatch(password) || string.IsNullOrWhiteSpace(password)) | ||
throw new ArgumentException("Invalid password"); | ||
_users.Add(new User(email, password)); | ||
} | ||
|
||
public List<User> GetUsers() | ||
{ | ||
return _users; | ||
} | ||
|
||
private void EnsureAdminExists(List<User> users) | ||
{ | ||
if (_users.Any(user => user.IsAdmin == true)) | ||
return; | ||
if (!_users.Any(user => user.IsAdmin == true)) | ||
_users.Prepend(new User("[email protected]","Abdurahmon0412",true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N27_HT2.Enums | ||
{ | ||
public enum Topics | ||
{ | ||
//- Topics enum dan foydalaning(Fun, IT, Gaming, Business) | ||
Fun, | ||
IT, | ||
Gaming, | ||
Business | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using N27_HT2.Enums; | ||
|
||
namespace N27_HT2.Models | ||
{ | ||
public class VideoPost | ||
{ | ||
//- VideoPost modelidan foydalaning(id, title, description, likes, dislikes, topic ) | ||
public Guid Id { get; set; } | ||
public string Title { get; set; } | ||
public string Description { get; set; } | ||
public int Likes { get; set; } | ||
public int Dislikes { get; set; } | ||
public Topics Topic { get; set; } | ||
|
||
public VideoPost() { } | ||
public VideoPost(string title, string description, int likes, int dislikes, Topics topic) | ||
{ | ||
Id = Guid.NewGuid(); | ||
Title = title; | ||
Description = description; | ||
Likes = likes; | ||
Dislikes = dislikes; | ||
Topic = topic; | ||
|
||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{Title} {Description} {Likes} {Dislikes} {Topic.ToString()}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//using System; | ||
|
||
//N27 - HT2 - min, max, average, sum, group, distinct | ||
|
||
//- Topics enum dan foydalaning(Fun, IT, Gaming, Business) | ||
|
||
//- VideoPost modelidan foydalaning(id, title, description, likes, dislikes, topic ) | ||
//-VideoPost tipidagi listga 10 ta video qo'shing | ||
|
||
//ulardan quyidagilarni ekranga chiqaring | ||
//- eng ko'p like olgani | ||
//- eng kam dislike olgani | ||
//- likelar o'rtachasi | ||
//- barcha videolardagi dislikelar soni | ||
//- videolarni faqat title va description bo'yicha projetion qilib ( Select ) | ||
//- videolardan topic bo'yicha unique qilib ( Distinct ) | ||
//- videolarni topic bo'yicha guruhlab | ||
|
||
|
||
using N27_HT2.Enums; | ||
using N27_HT2.Models; | ||
using N27_HT2.Services; | ||
|
||
var videoPostService = new VideoPostService(); | ||
videoPostService.Add(new VideoPost("Video1 ", "Description1" , 15,5, Topics.Fun)); | ||
videoPostService.Add(new VideoPost("Video2 ", "Description2" ,10,2,Topics.IT )); | ||
videoPostService.Add(new VideoPost("Video3 ", "Description3" ,20, 8, Topics.Gaming)); | ||
videoPostService.Add(new VideoPost("Video4 ", "Description4" ,8,3,Topics.Business )); | ||
videoPostService.Add(new VideoPost("Video5 ", "Description5" ,12 ,1,Topics.Fun)); | ||
videoPostService.Add(new VideoPost("Video6 ", "Description6" ,18 ,4,Topics.IT)); | ||
videoPostService.Add(new VideoPost("Video7 ", "Description7" ,5 ,2,Topics.Gaming)); | ||
videoPostService.Add(new VideoPost("Video8 ", "Description8" ,30 ,10,Topics.Business)); | ||
videoPostService.Add(new VideoPost("Video9 ", "Description9" , 7,0,Topics.Fun)); | ||
videoPostService.Add(new VideoPost("Video10 ", "Description10",25,6,Topics.IT )); | ||
|
||
videoPostService.MostLikedVideo(); | ||
videoPostService.LeastDislikedVideo(); | ||
videoPostService.AverageLikes(); | ||
videoPostService.TotalDislike(); | ||
videoPostService.VideoProjections(); | ||
videoPostService.UniqueTopics(); | ||
videoPostService.GroupedByTopic(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using N27_HT2.Enums; | ||
using N27_HT2.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N27_HT2.Services | ||
{ | ||
public class VideoPostService | ||
{ | ||
//-VideoPost tipidagi listga 10 ta video qo'shing | ||
|
||
//ulardan quyidagilarni ekranga chiqaring | ||
//- eng ko'p like olgani | ||
//- eng kam dislike olgani | ||
//- likelar o'rtachasi | ||
//- barcha videolardagi dislikelar soni | ||
//- videolarni faqat title va description bo'yicha projetion qilib ( Select ) | ||
//- videolardan topic bo'yicha unique qilib ( Distinct ) | ||
//- videolarni topic bo'yicha guruhlab | ||
private List<VideoPost> _videoPostList; | ||
|
||
public VideoPostService() | ||
{ | ||
_videoPostList = new List<VideoPost>(); | ||
} | ||
public void Add(VideoPost videoPsot) | ||
{ | ||
_videoPostList.Add(videoPsot); | ||
} | ||
|
||
public void MostLikedVideo() | ||
{ | ||
Console.WriteLine( _videoPostList.OrderByDescending(post => post.Likes).First()); | ||
} | ||
|
||
public void LeastDislikedVideo() | ||
{ | ||
Console.WriteLine(_videoPostList.OrderBy(post => post.Dislikes).First()); | ||
} | ||
|
||
public void AverageLikes() | ||
{ | ||
Console.WriteLine(_videoPostList.Average(post => post.Likes)); | ||
} | ||
|
||
public void TotalDislike() | ||
{ | ||
Console.WriteLine( _videoPostList.Sum(post => post.Dislikes)); | ||
} | ||
|
||
public void VideoProjections() | ||
{ | ||
_videoPostList.Select(post | ||
=> new { post.Title, post.Description }) | ||
.ToList().ForEach(post | ||
=> Console.WriteLine(post.Title + " " + post.Description)); | ||
} | ||
|
||
public void UniqueTopics() | ||
{ | ||
_videoPostList.Select(post => post.Topic).Distinct() | ||
.ToList().ForEach(post => Console.WriteLine(post.ToString())); | ||
} | ||
|
||
public void GroupedByTopic() | ||
{ | ||
var groupedByTopic = _videoPostList.GroupBy(post => post.Topic); | ||
Console.WriteLine("\nVideolarni topic bo'yicha guruhlab:"); | ||
foreach (var group in groupedByTopic) | ||
{ | ||
Console.WriteLine($"Topic: {group.Key}"); | ||
foreach (var video in group) | ||
{ | ||
Console.WriteLine($" {video.Title}"); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
} |