public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Notification { Type = NotificationType.Success }; try { using (var Context = Createcontext()) { AdditionalCondition additionalCondition = Context.AdditionalCondition.FirstOrDefault(o => o.AdditionalConditionID == id); if (additionalCondition == null) { notification = new Notification { Type = NotificationType.Error, Message = "Can't Find Data" }; return(false); } Context.AdditionalCondition.Remove(additionalCondition); Context.SaveChanges(); } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.AdditionalConditionDTO additionalConditionDTO = ((JObject)dtoItem).ToObject <DTO.AdditionalConditionDTO>(); notification = new Notification { Type = NotificationType.Success }; try { using (var context = Createcontext()) { AdditionalCondition additionalCondition = new AdditionalCondition(); if (id == 0) { context.AdditionalCondition.Add(additionalCondition); } if (id > 0) { additionalCondition = context.AdditionalCondition.FirstOrDefault(o => o.AdditionalConditionID == id); if (additionalCondition == null) { notification = new Notification { Type = NotificationType.Error, Message = "Can't Find Data" }; return(false); } } this.converter.DTO2DB_AdditionalCondition(additionalConditionDTO, ref additionalCondition); additionalCondition.UpdateDate = DateTime.Now; additionalCondition.UpdateBy = userId; context.SaveChanges(); dtoItem = this.GetData(additionalCondition.AdditionalConditionID, out notification); } return(true); } catch (Exception ex) { notification = new Notification { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public void DTO2DB_AdditionalCondition(DTO.AdditionalConditionDTO dto, ref AdditionalCondition db) { AutoMapper.Mapper.Map <DTO.AdditionalConditionDTO, AdditionalCondition>(dto, db); }