/// <summary> /// Updates the deal. /// </summary> /// <param name="dealId"></param> /// <param name="updateModel"></param> /// <returns></returns> public async Task <DealDto> UpdateDeal(Guid dealId, UpdateDealDto updateModel) { if (!validationContext.IsValid) { return(null); } var existingDeal = await unitOfWork.GetRepository <Deal>() .GetByIdAsync(dealId); if (existingDeal == null) { return(null); } if (updateModel.Images.Any()) { existingDeal.Images = updateModel.Images .Select(e => new DealImage { Path = e, Id = Guid.NewGuid() }) .ToList(); } mapper.Map <UpdateDealDto, Deal>(updateModel, existingDeal); unitOfWork.GetRepository <Deal>().Update(existingDeal); await unitOfWork.SaveAsync(); return(mapper.Map <Deal, DealDto>(existingDeal)); }
public async Task <string> UpdateDeals(UpdateDealDto UpdateDealDto) { DateTime Timezone = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Presentdate, TimeZoneInfo.Local.Id, UpdateDealDto.CountryTimezone); var DealDetails = Repository.SingleOrDefault(x => x.Id == UpdateDealDto.DealId); if (DealDetails.EndDate > Timezone && (DealDetails.StartDate > Timezone || DealDetails.StartDate == UpdateDealDto.StartDate)) { if (UpdateDealDto.EndDate > Timezone && UpdateDealDto.EndDate > UpdateDealDto.StartDate) { if (!string.IsNullOrEmpty(UpdateDealDto.DealName)) { DealDetails.DealName = UpdateDealDto.DealName; } if (!string.IsNullOrEmpty(UpdateDealDto.DealCode)) { DealDetails.DealCode = UpdateDealDto.DealCode; } if (!string.IsNullOrEmpty(UpdateDealDto.Countries)) { await _MerchantDealService.deleteMerchantDeal(UpdateDealDto.DealId); await _MerchantDealService.InsertMerchantDealDetails(UpdateDealDto.MerchantId, UpdateDealDto.Countries, UpdateDealDto.DealId); DealDetails.Country = UpdateDealDto.Countries; } if (!string.IsNullOrEmpty(UpdateDealDto.EnglishImage)) { DealDetails.EnglishImage = UpdateDealDto.EnglishImage; } if (!string.IsNullOrEmpty(UpdateDealDto.ArabicImage)) { DealDetails.ArabicImage = UpdateDealDto.ArabicImage; } if (!string.IsNullOrEmpty(UpdateDealDto.DealURL)) { DealDetails.DealURL = UpdateDealDto.DealURL; } if (!string.IsNullOrEmpty(UpdateDealDto.DealDescription)) { DealDetails.DealDescription = UpdateDealDto.DealDescription; } if (!string.IsNullOrEmpty(UpdateDealDto.StartDate.ToString())) { DealDetails.StartDate = UpdateDealDto.StartDate; } if (!string.IsNullOrEmpty(UpdateDealDto.EndDate.ToString())) { DealDetails.EndDate = UpdateDealDto.EndDate; } if (!string.IsNullOrEmpty(UpdateDealDto.CountryTimezone.ToString())) { DealDetails.TimeZone = UpdateDealDto.CountryTimezone; } await Repository.UpdateAsync(DealDetails); return("Deal updated successfully"); } else if (UpdateDealDto.EndDate < Timezone) { return("Please select the end date is greater then present date"); } else { return("Please select the end date is greater then start date."); } } else if (DealDetails.EndDate < Timezone) { return("Sorry you deal was expired"); } else { return("Sorry you are not allowed to update, deal is live now"); } }
public async Task <IActionResult> UpdateDeals([FromBody] UpdateDealDto UpdateDealDto) { string Dealupdatestatus = string.Empty; try { strImagePath = _configuration["FilePath:ImagePath"] + "DealsImages/"; if (!Directory.Exists(strImagePath)) { Directory.CreateDirectory(strImagePath); } if (!String.IsNullOrEmpty(UpdateDealDto.EnglishImage)) { if (UpdateDealDto.EnglishImage.Substring(UpdateDealDto.EnglishImage.Length - 3) != "jpg") { if (!String.IsNullOrEmpty(UpdateDealDto.EnglishImage)) { Byte[] EnglishimageByteData = Convert.FromBase64String(UpdateDealDto.EnglishImage); var Englishfs = new BinaryWriter(new FileStream(strImagePath + DealEnglishImages + ".jpg", FileMode.Create, FileAccess.Write)); Englishfs.Write(EnglishimageByteData); Englishfs.Close(); UpdateDealDto.EnglishImage = DealEnglishImages + ".jpg"; } } else { UpdateDealDto.EnglishImage = ""; } } else { UpdateDealDto.EnglishImage = ""; } if (!String.IsNullOrEmpty(UpdateDealDto.ArabicImage)) { if (UpdateDealDto.ArabicImage.Substring(UpdateDealDto.ArabicImage.Length - 3) != "jpg") { if (!String.IsNullOrEmpty(UpdateDealDto.ArabicImage)) { Byte[] ArabicimageByteData = Convert.FromBase64String(UpdateDealDto.ArabicImage); var Arabicfs = new BinaryWriter(new FileStream(strImagePath + DealArabicImages + ".jpg", FileMode.Create, FileAccess.Write)); Arabicfs.Write(ArabicimageByteData); Arabicfs.Close(); UpdateDealDto.ArabicImage = DealArabicImages + ".jpg"; } } else { UpdateDealDto.ArabicImage = ""; } } else { UpdateDealDto.ArabicImage = ""; } Dealupdatestatus = await _DealsService.UpdateDeals(UpdateDealDto); if (Dealupdatestatus == "Deal updated successfully") { return(Ok(new GenericResultDto <string> { Result = Dealupdatestatus })); } return(BadRequest(new GenericResultDto <string> { Result = Dealupdatestatus })); } catch (Exception err) { return(BadRequest(new GenericResultDto <string> { Result = err.Message })); } }