Skip to content

Commit

Permalink
HomeTask fill done is markdone
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 15, 2023
1 parent c9af020 commit 3599c5b
Show file tree
Hide file tree
Showing 17 changed files with 392 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.Homeworks/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Homeworks/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Homeworks/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Homeworks/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N23", "N23", "{ADD83ED5-61A
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N23_HT1", "N23_HT1", "{CD3DA6AB-7CBA-4BC7-8786-546A6D25D77F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N23_HT1", "N23_HT1\N23_HT1.csproj", "{F36BCA84-3D44-4FE4-9F17-364841C17BD2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N23_HT1", "N23_HT1\N23_HT1.csproj", "{F36BCA84-3D44-4FE4-9F17-364841C17BD2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N23_HT2", "N23_HT2", "{BC687718-A58E-4FE8-843D-A519D0CBE24B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N23_HT2", "N23_HT2\N23_HT2.csproj", "{436DDA7F-BCFF-4A0A-8C40-AFF08569297B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N23_HT2", "N23_HT2\N23_HT2.csproj", "{436DDA7F-BCFF-4A0A-8C40-AFF08569297B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N24", "N24", "{2546A077-DCDE-4476-A4B4-78B389A17604}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N23_HT24", "N23_HT24\N23_HT24.csproj", "{426A261F-A5DE-4783-A304-09AE82965733}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -359,6 +363,10 @@ Global
{436DDA7F-BCFF-4A0A-8C40-AFF08569297B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{436DDA7F-BCFF-4A0A-8C40-AFF08569297B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{436DDA7F-BCFF-4A0A-8C40-AFF08569297B}.Release|Any CPU.Build.0 = Release|Any CPU
{426A261F-A5DE-4783-A304-09AE82965733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{426A261F-A5DE-4783-A304-09AE82965733}.Debug|Any CPU.Build.0 = Debug|Any CPU
{426A261F-A5DE-4783-A304-09AE82965733}.Release|Any CPU.ActiveCfg = Release|Any CPU
{426A261F-A5DE-4783-A304-09AE82965733}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -432,6 +440,7 @@ Global
{F36BCA84-3D44-4FE4-9F17-364841C17BD2} = {CD3DA6AB-7CBA-4BC7-8786-546A6D25D77F}
{BC687718-A58E-4FE8-843D-A519D0CBE24B} = {ADD83ED5-61AE-4725-8B65-2327B01FF147}
{436DDA7F-BCFF-4A0A-8C40-AFF08569297B} = {BC687718-A58E-4FE8-843D-A519D0CBE24B}
{426A261F-A5DE-4783-A304-09AE82965733} = {2546A077-DCDE-4476-A4B4-78B389A17604}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
2 changes: 1 addition & 1 deletion N23_HT2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
|| user.LastName.Contains(keyvord, StringComparison.OrdinalIgnoreCase)
|| user.EmailAddress.Contains(keyvord, StringComparison.OrdinalIgnoreCase)).ToList()
.ForEach(user =>
Console.WriteLine($"{user.FirstName.PadRight(15)} {user.LastName.PadRight(15)} - {user.EmailAddress}"));
Console.WriteLine($"{user.FirstName.PadRight(15)} {user.LastName.PadRight(15)} {user.EmailAddress}"));


21 changes: 21 additions & 0 deletions N23_HT24/Interfaces/IUserCredentialsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using N23_HT24.Models;

namespace N23_HT24.Services
{
public interface IUserCredentialsService
{
//IUserCredentialsService dan foydalaning
//unda quyidagi methodlar bo'lsin

//- Add ( userId, password ) -password ni strong ekanligini regex bilan tekshirsin ( 8 <= simvol, 1 <= katta harf, 1 <= son ), valid bo'lsa qo'shsin va credential ni qaytarsin bo'lmasa exception
//- GetByUserId ( userId ) -user Id bo'yicha credential ni topib qaytarsin, bo'lmasa null
public UserCredentials Add(Guid userId,string password);
public UserCredentials GetByUserId(Guid userId);

}
}
33 changes: 33 additions & 0 deletions N23_HT24/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using N23_HT24.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N23_HT24.Services
{
public interface IUserService
{
//IUserService dan foydalaning
//unda quyidagi methodlar bo'lsin

//- Get ( pageSize, pageToken ) -userlarni pagination bian qaytarsin
//- Search ( searchKeyword, pageSize, pageToken ) -userlar ni kalit so'z bo'yicha qidirib pagination bilan qaytarsin
//- Filter ( userFilterModel ) -userlarni filter qilib pagination bilan qaytarsin
//- Add ( firstname, lastname, emailAddress ) -email address unique bo'lsa user ni qo'shsin va qaytarsin, bo'lmasa exception
//- Update ( user ) -userlar ichidan berilgan user borligini topib, update qilsin va qaytarsin, bo'lmasa exception
//- Delete ( id ) -userlar ichidan berilgan id bo'yicha user borligini topib IsDeleted true qilsin, bo'lmasa exception


public List<User>? Get(int pagesize, int pagetoken);
public List<User> Search(string searchkeyword, int pagesize, int pagetoken);
public List<User> Filter(UserFilterModel userFilterModel);
public User Add(string firstname, string lastname, string emailaddress);
public User Update(User user);
public void Delete(Guid id);



}
}
17 changes: 17 additions & 0 deletions N23_HT24/Models/FilterModel.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 N23_HT24.Models
{
public abstract class FilterModel
{
//FilterModel abstrakt modeldan foydalaning ( pageSize, pageToken )
public int PageSize { get; set; }
public int PageToken { get; set; }


}
}
27 changes: 27 additions & 0 deletions N23_HT24/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N23_HT24.Models
{
public class User
{
//User modelidan foydalaning ( id, firstname, lastname, emailAddress, isDeleted )
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public bool isDeleted { get; set; }

public User(string firstName, string lastName, string emailAddress)
{
Id = Guid.NewGuid();
FirstName = firstName;
LastName = lastName;
EmailAddress = emailAddress;
this.isDeleted = false;
}
}
}
23 changes: 23 additions & 0 deletions N23_HT24/Models/UserCredentials.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N23_HT24.Models
{
public class UserCredentials
{
//UserCredentials modelidan foydalaning ( id, password, userId )
public Guid Id { get; set; }
public string password { get; set; }
public Guid UserId { get; set; }

public UserCredentials(string password, Guid userId)
{
Id = Guid.NewGuid();
this.password = password;
UserId = userId;
}
}
}
15 changes: 15 additions & 0 deletions N23_HT24/Models/UserFilterModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N23_HT24.Models
{
public class UserFilterModel:FilterModel
{
//UserFilterModel dan foydalaning ( firstname?, lastname? ) u FilterModel dan inheritance olgan bo'lsin
public string? FirstName { get; set; }
public string? LastName { get; set;}
}
}
10 changes: 10 additions & 0 deletions N23_HT24/N24_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>
38 changes: 38 additions & 0 deletions N23_HT24/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Net;
using N23_HT24.Services;

//PS : UserCredentialsService da parameterized konstruktor bo'lsin, u orqali
//IUserService va IUserCredentialsService implementatsiya qilgan tipdan object berib, fieldga saqlanadigan bo'lsin
//( biz buni AccountService misolida ko'rganmiz )

//- dasturda UserCredentialsService dan object yarating
//- bir nechta userlar qo'shing va natijasini ekranga chiqaring
//- konsoldan keyword kiritib, userlar ni search qilib ekranga chiqaring
var userService = new UserService();
var UserCredentials = new UserCredentialsService();
var register = new RegistrationService(userService,UserCredentials);


register.Register("John", "Doe", "[email protected]", "securepassword123");
register.Register("Jane", "Smith", "[email protected]", "strongpassword456");
register.Register("Michael", "Johnson", "[email protected]", "mypassword789");
register.Register("Emily", "Brown", "[email protected]", "safepassword2023");
register.Register("William", "Jones", "[email protected]", "complexpass321");
register.Register("Olivia", "Garcia", "[email protected]", "password987654");
register.Register("James", "Miller", "[email protected]", "myp@ssw0rd");
register.Register("Sophia", "Davis", "[email protected]", "newpassw0rd");
register.Register("Benjamin", "Martinez", "[email protected]", "securepass123");
register.Register("Ava", "Rodriguez", "[email protected]", "password2023");
register.Register("Liam", "Lopez", "[email protected]", "strongpass789");
register.Register("Emma", "Hernandez", "[email protected]", "safe123456");
register.Register("Noah", "Moore", "[email protected]", "password21");
register.Register("Isabella", "Lee", "[email protected]", "passcode123");
register.Register("Ethan", "Clark", "[email protected]", "newpassword456");
register.Register("Mia", "Lewis", "[email protected]", "securepassw0rd");
register.Register("Aiden", "Walker", "[email protected]", "password987");
register.Register("Lily", "Hall", "[email protected]", "strongpass2023");
register.Register("Carter", "Young", "[email protected]", "safe456789");
register.Register("Grace", "Allen", "[email protected]", "mypassword123");

//userService.Get(10,1).ForEach(user => Console.WriteLine($"{user.FirstName} {user.LastName} - {user.EmailAddress}"));
userService.Search("e",10,1).ForEach(user => Console.WriteLine($"{user.FirstName} {user.LastName} - {user.EmailAddress}"));
34 changes: 34 additions & 0 deletions N23_HT24/Services/RegistrationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace N23_HT24.Services;

public class RegistrationService
{
//RegistrationService dan foydalaning
//unda quyidagi methodlar bo'lsin

//- Register ( firstName, lastName, emailAddress, password ) -UserService orqali userni UserCredentialsService
//orqali credentialni qo'shsin, hammasi muvaffaqqiyatli bo'lsa true, bo'lmasa false qaytarsin


private readonly IUserService _userService;
private readonly IUserCredentialsService _credentialsService;

public RegistrationService(IUserService userService, IUserCredentialsService credentialsService)
{
_userService = userService;
_credentialsService = credentialsService;
}

public bool Register(string firstName, string lastName, string emailAddress, string password)
{
try
{
var user = _userService.Add(firstName, lastName, emailAddress);
_credentialsService.Add(user.Id, password);
return true;
}
catch
{
return false;
}
}
}
42 changes: 42 additions & 0 deletions N23_HT24/Services/UserCredentialsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using N23_HT24.Models;

namespace N23_HT24.Services
{
public class UserCredentialsService:IUserCredentialsService
{
//IUserCredentialsService dan foydalaning
//unda quyidagi methodlar bo'lsin
//- Add ( userId, password ) -password ni strong ekanligini regex bilan tekshirsin ( 8 <= simvol, 1 <= katta harf, 1 <= son ), valid bo'lsa qo'shsin va credential ni qaytarsin bo'lmasa exception
//- GetByUserId ( userId ) -user Id bo'yicha credential ni topib qaytarsin, bo'lmasa null
private List<UserCredentials> _userCredentials = new List<UserCredentials>();

public UserCredentials Add(Guid userId, string password)
{
if (Regex.IsMatch(password, @"^(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{8,}$"))
{
var userCradential = new UserCredentials(password, userId);
_userCredentials.Add(userCradential);
return userCradential;

}
else
{
throw new InvalidOperationException("User credentials Invalid");
}

}

public UserCredentials? GetByUserId(Guid userId)
{
return _userCredentials.Any(user => user.Id == userId)
? _userCredentials.Find(user => user.Id == userId)
: null;
}
}
}
Loading

0 comments on commit 3599c5b

Please sign in to comment.