Skip to content

Commit

Permalink
Group is mark done
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 18, 2023
1 parent 72983e6 commit dd7a702
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 3 deletions.
22 changes: 22 additions & 0 deletions Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N26_HT1", "N26_HT1\N26_HT1.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N26_HT2", "N26_HT2\N26_HT2.csproj", "{C178D0BF-BD12-4985-B3E1-512E6AAAFC54}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N27", "N27", "{FBDAB7B5-12E3-44DF-93A4-0DFF77A9787A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N27_HT1", "N27_HT1", "{0656C2F3-476B-4294-BD1B-FECD6E3A6611}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N27_HT1", "N27_HT1\N27_HT1.csproj", "{F6594D8B-EF02-41AF-B234-E58D02F07E6B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N27_HT1", "N27_HT1", "{6845C004-A5D3-40A5-95FB-BEC903C07C3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N27_HT2", "N27_HT2\N27_HT2.csproj", "{A2E27C2E-6CE1-47E3-9985-88F9098A48F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -389,6 +399,14 @@ Global
{C178D0BF-BD12-4985-B3E1-512E6AAAFC54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C178D0BF-BD12-4985-B3E1-512E6AAAFC54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C178D0BF-BD12-4985-B3E1-512E6AAAFC54}.Release|Any CPU.Build.0 = Release|Any CPU
{F6594D8B-EF02-41AF-B234-E58D02F07E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6594D8B-EF02-41AF-B234-E58D02F07E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6594D8B-EF02-41AF-B234-E58D02F07E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6594D8B-EF02-41AF-B234-E58D02F07E6B}.Release|Any CPU.Build.0 = Release|Any CPU
{A2E27C2E-6CE1-47E3-9985-88F9098A48F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2E27C2E-6CE1-47E3-9985-88F9098A48F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2E27C2E-6CE1-47E3-9985-88F9098A48F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2E27C2E-6CE1-47E3-9985-88F9098A48F5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -466,6 +484,10 @@ Global
{71BD1DED-EDCA-46DE-ABFD-BDC682E26100} = {F9C8D322-69BC-4757-A70E-E3593F8DD840}
{050A82DA-46BF-4FB9-910C-85849FDECDE9} = {19A44840-2DDD-4E39-BF10-AF0DB85A9CBE}
{C178D0BF-BD12-4985-B3E1-512E6AAAFC54} = {19A44840-2DDD-4E39-BF10-AF0DB85A9CBE}
{0656C2F3-476B-4294-BD1B-FECD6E3A6611} = {FBDAB7B5-12E3-44DF-93A4-0DFF77A9787A}
{F6594D8B-EF02-41AF-B234-E58D02F07E6B} = {0656C2F3-476B-4294-BD1B-FECD6E3A6611}
{6845C004-A5D3-40A5-95FB-BEC903C07C3D} = {FBDAB7B5-12E3-44DF-93A4-0DFF77A9787A}
{A2E27C2E-6CE1-47E3-9985-88F9098A48F5} = {6845C004-A5D3-40A5-95FB-BEC903C07C3D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
25 changes: 23 additions & 2 deletions N27_HT1/Models/User.cs
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: ******";
}
}
10 changes: 10 additions & 0 deletions N27_HT1/N27_HT1.csproj
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>
23 changes: 23 additions & 0 deletions N27_HT1/Program.cs
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));
43 changes: 42 additions & 1 deletion N27_HT1/Services/UserService.cs
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));
}
}
17 changes: 17 additions & 0 deletions N27_HT2/Enums/Topics.cs
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
}
}
37 changes: 37 additions & 0 deletions N27_HT2/Models/VideoPost.cs
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()}";
}
}
}
10 changes: 10 additions & 0 deletions N27_HT2/N27_HT2.csproj
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>
42 changes: 42 additions & 0 deletions N27_HT2/Program.cs
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();
84 changes: 84 additions & 0 deletions N27_HT2/Services/VideoPostService.cs
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}");
}
}
}


}
}

0 comments on commit dd7a702

Please sign in to comment.