public override bool DeleteData(int id, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; try { using (var context = CreatContext()) { ClientRelationshipType clientRelationshipType = context.ClientRelationshipType.FirstOrDefault(o => o.ClientRelationshipTypeID == id); if (clientRelationshipType == null) { notification = new Notification() { Type = NotificationType.Error }; return(false); } context.ClientRelationshipType.Remove(clientRelationshipType); 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 Notification notification) { DTO.ClientRelationshipTypeDto clientRelationshipTypeDto = ((JObject)dtoItem).ToObject <DTO.ClientRelationshipTypeDto>(); notification = new Notification() { Type = NotificationType.Success }; try { using (var context = this.CreatContext()) { ClientRelationshipType clientRelationshipType = new ClientRelationshipType(); if (id == 0) { context.ClientRelationshipType.Add(clientRelationshipType); } if (id > 0) { clientRelationshipType = context.ClientRelationshipType.FirstOrDefault(o => o.ClientRelationshipTypeID == id); if (clientRelationshipType == null) { notification = new Notification() { Type = NotificationType.Error, Message = "Can Not Find Data" }; return(false); } } this.Converter.DTO2DB_ClientRelationshipTypeMng(clientRelationshipTypeDto, ref clientRelationshipType); context.SaveChanges(); dtoItem = this.GetData(clientRelationshipType.ClientRelationshipTypeID, out notification); } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public bool UpdateOrder(int userId, object data, out Notification notification) { List <DTO.ClientRelationshipTypeDto> clientRelationshipTypeDto = ((JArray)data).ToObject <List <DTO.ClientRelationshipTypeDto> >(); notification = new Notification() { Type = NotificationType.Success }; try { using (var context = this.CreatContext()) { ClientRelationshipType clientRelationshipType = new ClientRelationshipType(); foreach (var item in clientRelationshipTypeDto) { if (item.isChange == true) { clientRelationshipType = context.ClientRelationshipType.FirstOrDefault(o => o.ClientRelationshipTypeID == item.ClientRelationshipTypeID); this.Converter.DTO2DB_ClientRelationshipTypeMng(item, ref clientRelationshipType); context.SaveChanges(); } } } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public void DTO2DB_ClientRelationshipTypeMng(DTO.ClientRelationshipTypeDto dto, ref ClientRelationshipType db) { AutoMapper.Mapper.Map <DTO.ClientRelationshipTypeDto, ClientRelationshipType>(dto, db); }