/// <summary> /// /// </summary> /// <param name="Id"></param> /// <returns></returns> public async Task <IActionResult> ConfirmPremiumOffer(int?id) { if (id == null) { return(new NotFoundViewResult("_Error404")); } try { var offer = await _premiumRepository.GetByIdWithIncludesAsync(id.Value); if (offer == null) { throw new Exception(); } offer.ModifiedBy = await GetCurrentUser(); offer.UpdateDate = DateTime.Now; offer.Status = 0; var result = await _premiumRepository.UpdateOfferAsync(offer); if (!result.Success) { throw new Exception(); } //deal with notification await _notificationHelper.DeleteOldByIdAsync(offer.OfferIdGuid); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } return(RedirectToAction(nameof(PremiumIndex))); }
public async Task <IActionResult> Edit(PremiumOfferViewModel model) { try { var current = await _premiumRepository.GetByIdAsync(model.Id); if (current == null) { return(new NotFoundViewResult("_Error404")); } var partner = await _partnerRepository.GetByIdAsync(model.Id); var flight = await _flightRepository.GetByIdAsync(model.FlightId); current.Flight = flight ?? null; current.Conditions = string.IsNullOrEmpty(model.Conditions) ? string.Empty : model.Conditions; current.Partner = partner; current.Quantity = model.Quantity; current.Price = model.Price; current.Status = 1; current.ModifiedBy = await GetCurrentUser(); current.UpdateDate = DateTime.UtcNow; var result = await _premiumRepository.UpdateOfferAsync(current); if (!result.Success) { return(new NotFoundViewResult("_Error404")); } //update notification to SuperUser result = await _notificationHelper.UpdateNotificationAsync(current.OfferIdGuid, UserType.SuperUser, ""); if (!result.Success) { //if notification does not exist, creates one await _notificationHelper.CreateNotificationAsync(current.OfferIdGuid, UserType.SuperUser, "", EnumHelper.GetType(current.Type)); } return(RedirectToAction(nameof(PremiumIndex))); } catch (Exception) { return(new NotFoundViewResult("_Error500")); } }