-
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
b274606
commit 13fdab3
Showing
8 changed files
with
218 additions
and
1 deletion.
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 |
---|---|---|
@@ -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(); | ||
|
||
} | ||
} |
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 N22_2_Hometask.Interfaces | ||
{ | ||
public interface IRewiev | ||
{ | ||
public Guid Id { get; set; } | ||
public int Star { get; set; } | ||
public string Massage { get; set; } | ||
|
||
|
||
} | ||
} |
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 @@ | ||
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}"; | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
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 @@ | ||
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}"; | ||
} | ||
} | ||
} |
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>net6.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,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(); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|