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 HttpStatusCode UpdateAttributeById(int attributeId, UpdateAttributeDto updateAttributeDto) { var response = _attributeRepository.UpdateAttribute(attributeId, updateAttributeDto); switch (response) { case HttpStatusCode.OK: return(HttpStatusCode.OK); case HttpStatusCode.InternalServerError: return(HttpStatusCode.InternalServerError); default: return(HttpStatusCode.NotFound); } }