public IActionResult OfferDetails(OffersViewModel offersData) { this.logger.LogInformation("Offers Controller / OfferDetails: offerGuId {0}", JsonSerializer.Serialize(offersData)); try { var currentUserDetail = this.usersRepository.GetPartnerDetailFromEmail(this.CurrentUserEmailAddress); if (offersData != null && offersData.OfferAttributes != null) { // query var validItems = offersData.OfferAttributes.Where(i => i.IsRemove == false); foreach (var offerAttribute in validItems) { var newOfferAttribute = new OfferAttributes() { Id = offerAttribute.AttributeID, ParameterId = offerAttribute.ParameterId, DisplayName = offerAttribute.DisplayName, Description = offerAttribute.Description, ValueTypeId = offerAttribute.ValueTypeId, FromList = offerAttribute.FromList, ValuesList = offerAttribute.ValuesList, Max = offerAttribute.Max, Min = offerAttribute.Min, Type = offerAttribute.Type, DisplaySequence = offerAttribute.DisplaySequence, Isactive = offerAttribute.Isactive, IsRequired = offerAttribute.IsRequired, IsDelete = offerAttribute.IsDelete, CreateDate = DateTime.Now, UserId = currentUserDetail == null ? 0 : currentUserDetail.UserId, OfferId = offersData.OfferGuid, }; this.offersAttributeRepository.Add(newOfferAttribute); } var valueTypes = this.valueTypesRepository.GetAll().ToList(); this.ViewBag.ValueTypes = new SelectList(valueTypes, "ValueTypeId", "ValueType"); this.TempData["ShowWelcomeScreen"] = "True"; } this.ModelState.Clear(); return(this.RedirectToAction(nameof(this.OfferDetails), new { @offerGuId = offersData.OfferGuid })); } catch (Exception ex) { this.logger.LogError(ex, ex.Message); return(this.View("Error", ex)); } }
/// <summary> /// Gets this instance. /// </summary> /// <param name="offerAttributes">The offer attributes.</param> /// <returns> /// Id of the newly added offer attribute. /// </returns> public int?Add(OfferAttributes offerAttributes) { if (offerAttributes != null) { var existingOfferAttribute = this.context.OfferAttributes.Where(s => s.Id == offerAttributes.Id).FirstOrDefault(); if (existingOfferAttribute != null) { existingOfferAttribute.ParameterId = offerAttributes.ParameterId; existingOfferAttribute.DisplayName = offerAttributes.DisplayName; existingOfferAttribute.Description = offerAttributes.Description; existingOfferAttribute.ValueTypeId = offerAttributes.ValueTypeId; existingOfferAttribute.FromList = offerAttributes.FromList; existingOfferAttribute.ValuesList = offerAttributes.ValuesList; existingOfferAttribute.Max = offerAttributes.Max; existingOfferAttribute.Min = offerAttributes.Min; existingOfferAttribute.Type = offerAttributes.Type; existingOfferAttribute.DisplaySequence = offerAttributes.DisplaySequence; existingOfferAttribute.Isactive = offerAttributes.Isactive; existingOfferAttribute.UserId = offerAttributes.UserId; existingOfferAttribute.OfferId = offerAttributes.OfferId; existingOfferAttribute.IsRequired = offerAttributes.IsRequired; existingOfferAttribute.IsDelete = offerAttributes.IsDelete; this.context.OfferAttributes.Update(existingOfferAttribute); this.context.SaveChanges(); return(existingOfferAttribute.Id); } else { this.context.OfferAttributes.Add(offerAttributes); this.context.SaveChanges(); return(offerAttributes.Id); } } return(null); }