예제 #1
0
        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);
    }
예제 #3
0
        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));
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
0
        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>()));
            }
        }
예제 #8
0
        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
            });
        }