public ServiceResultModel <AttributeVM> UpdateAttribute(AttributeVM model) { using (EFBookingContext context = new EFBookingContext()) { var currentItem = context.Attributes.FirstOrDefault(p => p.Id == model.Id); if (currentItem != null) { if (context.Attributes.Any(p => p.Id != model.Id && (p.Name.Equals(model.Name) && p.AttributeType == model.AttributeType))) { return(new ServiceResultModel <AttributeVM> { Code = ServiceResultCode.Duplicate, Data = currentItem.MapToViewModel <AttributeVM>(), ResultType = OperationResultType.Warn, Message = "This title using other records " }); } currentItem.Name = model.Name; currentItem.Description = model.Description; context.Entry <Attributes>(currentItem).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } return(ServiceResultModel <AttributeVM> .OK(currentItem.MapToViewModel <AttributeVM>())); } }
public void AddAttribute(Guid guid, string name) { AttributeVM attrVM = new AttributeVM(); attrVM.Name = name; attrVM.Guid = guid; this.Attributes.Add(guid, attrVM); }
public ActionResult Edit(long Id) { AttributeDTO attributeDTO = _ManageAttributeGroup.GetAttributeById(Id); Mapper.Initialize(c => c.CreateMap <AttributeDTO, AttributeVM>()); AttributeVM attribute = Mapper.Map <AttributeDTO, AttributeVM>(attributeDTO); return(View(attribute)); }
public ActionResult Add(AttributeVM attribute) { if (ModelState.IsValid) { Mapper.Initialize(c => c.CreateMap <AttributeVM, AttributeDTO>()); AttributeDTO dto = Mapper.Map <AttributeVM, AttributeDTO>(attribute); OperationDetails op = _ManageAttributeGroup.AddAttribute(dto); return(Json(new { Succedeed = op.Succedeed, message = op.Message })); } else { return(View(attribute)); } }
public JsonResult SaveAttribute(AttributeVM model) { if (!ModelState.IsValid) { return(base.JSonModelStateHandle()); } ServiceResultModel <AttributeVM> serviceResult = model.Id <= 0 ? _attributeService.SaveAttribute(model) : _attributeService.UpdateAttribute(model); return(Json(base.UIResponse = new UIResponse() { ResultType = serviceResult.ResultType, Data = serviceResult.Data, Message = serviceResult.Message }, JsonRequestBehavior.AllowGet)); }
public ActionResult Add() { //List<AttributeGroupDTO> groupsDTO = _ManageAttributeGroup.GetAllAttributeGroups(); //List<SelectListItem> groups = groupsDTO.ConvertAll(a => //{ // return new SelectListItem() // { // Text = a.ArabicName, // Value = a.Id.ToString(), // Selected = false // }; //}); //ViewBag.Groups = groups; AttributeVM attribute = new AttributeVM(); attribute.Groups = _ManageAttributeGroup.GetAllAttributeGroups(); return(View(attribute)); }
public ServiceResultModel <AttributeVM> SaveAttribute(AttributeVM model) { using (EFBookingContext context = new EFBookingContext()) { if (context.Attributes.Any(p => p.Name.Equals(model.Name) && p.AttributeType == model.AttributeType)) { return(new ServiceResultModel <AttributeVM> { Code = ServiceResultCode.Duplicate, Data = model, ResultType = OperationResultType.Warn, Message = "This record already exitst " }); } var recordItem = context.Attributes.Add(model.MapToEntityModel <Attributes>()); context.SaveChanges(); return(ServiceResultModel <AttributeVM> .OK(recordItem.MapToViewModel <AttributeVM>())); } }
public async Task <JSONResponseVM> AddNewAttribute([FromBody] AttributeVM attr) { //check to see if admin //create new attibute. Have to use Data.Attribute because System.Attribute is also a thing Data.Attribute att = new Data.Attribute { name = attr.name, attribute_type_id = attr.attribute_type_id, image_src = attr.image_src, rarity = attr.rarity, attribute = await context.AttributeTypes.Where(a => a.attribute_type_id == attr.attribute_type_id).FirstOrDefaultAsync() }; context.Attributes.Add(att); context.SaveChanges(); return(new JSONResponseVM { success = true, message = "Successfully add new attribute: " + att.name }); }