Skip to content

Commit

Permalink
2 Task is mark done
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 11, 2023
1 parent b274606 commit 13fdab3
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Imtihon_Update", "Imtihon_U
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N22", "N22", "{40FDA0A2-3C89-426C-B3C5-37838F4864CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N22_WriteLlist", "N22_WriteLlist\N22_WriteLlist.csproj", "{22FF572D-A745-41FB-B4BD-48CFF604ADA0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N22_WriteLlist", "N22_WriteLlist\N22_WriteLlist.csproj", "{22FF572D-A745-41FB-B4BD-48CFF604ADA0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N22_2", "N22_2", "{966F0F80-9E8D-4F24-8B88-F053AA0627C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N22_2_Hometask", "N22_2_Hometask\N22_2_Hometask.csproj", "{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -327,6 +331,10 @@ Global
{22FF572D-A745-41FB-B4BD-48CFF604ADA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22FF572D-A745-41FB-B4BD-48CFF604ADA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22FF572D-A745-41FB-B4BD-48CFF604ADA0}.Release|Any CPU.Build.0 = Release|Any CPU
{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -394,6 +402,7 @@ Global
{0F11A119-2C25-46CF-AC3F-C66073C85C86} = {1B9C8189-61EE-400A-9EF2-5711CDBC0211}
{CD7B1616-9B70-4FC8-BB1A-3B41E766E078} = {0F11A119-2C25-46CF-AC3F-C66073C85C86}
{22FF572D-A745-41FB-B4BD-48CFF604ADA0} = {40FDA0A2-3C89-426C-B3C5-37838F4864CE}
{1D1007B9-DDE2-4645-B89F-342A2F4E0BB7} = {966F0F80-9E8D-4F24-8B88-F053AA0627C6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
22 changes: 22 additions & 0 deletions N22_2_Hometask/Interfaces/IReviewList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N22_2_Hometask.Interfaces
{
public interface IReviewList<TRewiew>where TRewiew : IRewiev
{
public void Add(TRewiew rewiew);
public void Update(Guid id, int star, string massage);

public void Remove(TRewiew rewiew);
public void Remove(Guid id);
public TRewiew? GetReview(Guid id);
public TRewiew GetReview(string massage);

public void GetOverallReview();

}
}
17 changes: 17 additions & 0 deletions N22_2_Hometask/Interfaces/IRewiev.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 N22_2_Hometask.Interfaces
{
public interface IRewiev
{
public Guid Id { get; set; }
public int Star { get; set; }
public string Massage { get; set; }


}
}
23 changes: 23 additions & 0 deletions N22_2_Hometask/Model/CrashReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using N22_2_Hometask.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N22_2_Hometask.Model
{
internal class CrashReport:IRewiev
{
public Guid Id { get; set; }
public int Star { get; set; }
public string Massage { get; set; }
public string Screenshot { get; set; }
public CrashReport(int star, string massage,string screenshot) => (Id, Star, Massage, Screenshot) = (Guid.NewGuid(), star, massage,screenshot);

public override string ToString()
{
return $"Star: {Star} - Massage {Massage}";
}
}
}
80 changes: 80 additions & 0 deletions N22_2_Hometask/Model/ReviewList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N22_2_Hometask.Interfaces
{
public class ReviewList<TRewiev> : IReviewList<TRewiev> where TRewiev : IRewiev
{
public ReviewList()
{
_reviewList = new List<TRewiev>();
}
private List<TRewiev> _reviewList;
public void Add(TRewiev rewiew)
{
_reviewList.Add(rewiew);
}


public TRewiev GetReview(Guid id)
{
var review = _reviewList.FirstOrDefault(rewiev => rewiev.Id == id);
if (review != null) return review;
return default(TRewiev);
}

public TRewiev GetReview(string massage)
{
var review = _reviewList.FirstOrDefault(rewiev => rewiev.Massage == massage);
if(review != null) return review;
return default(TRewiev);
}

public void Remove(Guid id)
{
var review = _reviewList.FirstOrDefault(review => review.Id == id);
_reviewList.Remove(review);

}

public void Remove(TRewiev rewiew)
{
_reviewList.Remove(rewiew);
}

public void Update(Guid id, int star, string massage)
{
var update = _reviewList.First(rewiev => rewiev.Id == id);
update.Star = star;
update.Massage = massage;
}

public void GetOverallReview()
{
var allReviewStar = true;

bool anyAdult = _reviewList.Any();
if (anyAdult == default)
{
Console.WriteLine("Be the first to leave a review for this product");
return;
}
bool allAdults = _reviewList.All(rewiev => rewiev.Star == 5);

if(allAdults == true)
{
Console.WriteLine("Great news! All reviews for this product are 5 - star ratings.");
}
var review = _reviewList.FirstOrDefault(review => review.Star == 1);
if(review != null)
{
Console.WriteLine(review.Massage);
}
}


}
}
23 changes: 23 additions & 0 deletions N22_2_Hometask/Model/Rewiev.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using N22_2_Hometask.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace N22_2_Hometask.Model
{
public class Rewiev : IRewiev
{
public Guid Id { get; set; }
public int Star { get; set; }
public string Massage { get; set; }

// New constructor
public Rewiev(int star, string massage) => (Id, Star, Massage) = (Guid.NewGuid(), star, massage);
public override string ToString()
{
return $"Star: {Star} - Massage {Massage}";
}
}
}
10 changes: 10 additions & 0 deletions N22_2_Hometask/N22_2_Hometask.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
33 changes: 33 additions & 0 deletions N22_2_Hometask/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using N22_2_Hometask.Interfaces;
using N22_2_Hometask.Model;

ReviewList<IRewiev> RewievList = new ReviewList<IRewiev>();
RewievList.GetOverallReview();

var review1 = new Rewiev(5, "MEssage 1 uchun");
var review2 = new Rewiev(2, "MEssage 2 uchun");
var review3 = new Rewiev(5, "MEssage 3 uchun");

var crash1 = new CrashReport(5, "For crash1 ", "bu path1");
var crash2 = new CrashReport(5, "For crash2 ", "bu path2");
var crash3 = new CrashReport(5, "For crash3 ", "bu path3");

RewievList.Add(review1);
RewievList.Add(review2);
RewievList.Add(review3);
RewievList.Add(crash1);
RewievList.Add(crash2);
RewievList.Add(crash3);

Console.WriteLine(RewievList.GetReview(review1.Id));
Console.WriteLine(RewievList.GetReview("MEssage 1 uchun"));
RewievList.Update(review2.Id, 1, "bu yangi 2 message");
RewievList.GetOverallReview();








0 comments on commit 13fdab3

Please sign in to comment.