public DataResponceModel <VatCalculationResponce> GetAmmountCalculationFromVat(string country, int vatRate, decimal vat) { var responce = new DataResponceModel <VatCalculationResponce>(); if (!IsValidCountry(country)) { responce.Message = "Error in country."; return(responce); } if (!IsValidVatRate(vatRate)) { responce.Message = $"Error: this rate [{vatRate}] is not valid for Austria"; return(responce); } if (!IsValiddecimalInputMoneyAmount(vat)) { responce.Message = $"Error: vat data is invalid"; return(responce); } responce.Model = new VatCalculationResponce() { Gross = Math.Round((100 + vatRate) * vat / vatRate, 2), Net = Math.Round(100 * vat / vatRate, 2), Vat = vat, VatRate = vatRate }; responce.Success = true; return(responce); }
public DataResponceModel <List <LessonProgressModel> > GetCompletedLessons(string userGuid) { var result = new DataResponceModel <List <LessonProgressModel> >(); if (!CheckUser(userGuid)) { result.Message = "It is problems with userGuid"; return(result); } result.Model = GetFinishedUniqueUserLessons(userGuid) .Select(x => new LessonProgressModel { LessonId = x.LessonId, LessonText = x.Lesson?.Text, EndDate = x.EndDate.Value, StartDate = x.StartDate }).ToList(); result.Success = true; return(result); //add Mapper to map models!!! }
public DataResponceModel <List <AchievementModel> > GetUserAchievement(string userGuid) { var result = new DataResponceModel <List <AchievementModel> >(); if (!CheckUser(userGuid)) { result.Message = "It is problems with userGuid"; return(result); } var userAchievements = new List <AchievementModel>(); var achievementList = _achievementsService.GetAllAchievements().ToList(); var finishedLessons = GetFinishedUniqueUserLessons(userGuid); var finishedChapter = GetFinishedChapters(finishedLessons); var finishedCourse = GetFinishedCourses(finishedLessons, finishedChapter); foreach (var achievement in achievementList) { switch (achievement.AchievementType) { case AchievementType.GotLessonsQuantity: var countFinishedLessons = finishedLessons.Count(); if (countFinishedLessons >= achievement.AchievementObjectIntData) { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, IsCompleted = true }); } else { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, Progress = countFinishedLessons.ToString() }); } break; case AchievementType.GotChapterQuantity: var countFinishedChapter = finishedChapter.Count(); if (countFinishedChapter >= achievement.AchievementObjectIntData) { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, IsCompleted = true }); } else { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, Progress = countFinishedChapter.ToString() }); } break; case AchievementType.GotCourse: var course = _coursesService.GetCorseById(achievement.AchievementObjectId); if (course == null) { result.Message = $"Problem with data achievement.Id[{achievement.Id}], achievement.AchievementObjectId[{achievement.AchievementObjectId}]"; return(result); } if (finishedCourse.FirstOrDefault(x => x.Id == achievement.AchievementObjectId) != null) { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, IsCompleted = true }); } else { userAchievements.Add(new AchievementModel { AchievementId = achievement.Id, AchievementName = achievement.Name, Progress = (course.Chapters?.Count - finishedChapter.Where(x => x.CourseId == course.Id)?.Count()).ToString() }); } break; case AchievementType.GotTimeFrame: break; default: break; } } result.Model = userAchievements; result.Success = true; return(result); }