public HttpStatusCode UpdateAttribute(int attributeId, UpdateAttributeDto updateAttributeDto) { if (updateAttributeDto.AttributeGroupId <= 0) { return(HttpStatusCode.NotFound); } DAL.Models.Attribute attribute = _ctx.Attributes.FirstOrDefault(f => f.Id == attributeId); attribute.Name = updateAttributeDto.AttributeName; attribute.Value = EnumHelper.GetValueType(updateAttributeDto.ValueTypeId); attribute.LastModifiedDate = DateTime.Now; AttributeGroup attributeGroup = _ctx.AttributeGroups.FirstOrDefault(f => f.Id == updateAttributeDto.AttributeGroupId); attribute.AttributeGroup = attributeGroup; attribute.AttributeGroupId = attributeGroup.Id; try { _ctx.Entry(attribute).State = EntityState.Modified; _ctx.SaveChanges(); return(HttpStatusCode.OK); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } }
public AttributeViewModel GetAttributeById(int attributeId) { DAL.Models.Attribute attribute = _ctx.Attributes.FirstOrDefault(f => f.Id == attributeId); AttributeGroup attributeGroup = _ctx.AttributeGroups.FirstOrDefault(f => f.Id == attribute.AttributeGroupId); AttributeViewModel attributeViewModel = AttributeFactory.AttributeToViewModel(attribute, attributeGroup.Name); return(attributeViewModel); }
public static DAL.Models.Attribute AttributeToDbo(CreateAttributeDto createAttributeDto, AttributeGroup attributeGroup) { var model = new DAL.Models.Attribute() { Name = createAttributeDto.AttributeName, Value = EnumHelper.GetValueType(createAttributeDto.ValueTypeId), AttributeGroupId = createAttributeDto.AttributeGroupId, AttributeGroup = attributeGroup, CreationDate = DateTime.Now }; return(model); }
public static AttributeViewModel AttributeToViewModel(DAL.Models.Attribute attribute, string attributeGroupName) { string valueType = EnumHelper.EnumValueTypeToString(attribute.Value); var attributeViewModel = new AttributeViewModel() { AttributeId = attribute.Id, AttributeName = attribute.Name, CreationDate = attribute.CreationDate, LastModifiedDate = attribute.LastModifiedDate, ValueType = valueType, AttributeGroupName = attributeGroupName }; return(attributeViewModel); }
public HttpStatusCode DeleteAttribute(int attributeId) { DAL.Models.Attribute attribute = _ctx.Attributes.FirstOrDefault(f => f.Id == attributeId); if (attribute == null) { return(HttpStatusCode.NotFound); } try { _ctx.Attributes.Remove(attribute); _ctx.SaveChanges(); return(HttpStatusCode.OK); } catch (Exception ex) { return(HttpStatusCode.InternalServerError); } }