コード例 #1
0
        public override bool DeleteData(int id, out Notification notification)
        {
            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var Context = CreateContext())
                {
                    CheckListGroup unit = Context.CheckListGroup.FirstOrDefault(o => o.CheckListGroupID == id);

                    if (unit == null)
                    {
                        notification = new Notification {
                            Type = NotificationType.Error, Message = "Can't Find Data"
                        };
                        return(false);
                    }

                    Context.CheckListGroup.Remove(unit);
                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
コード例 #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.CheckListGroupDTO checkListDTO = ((JObject)dtoItem).ToObject <DTO.CheckListGroupDTO>();

            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = CreateContext())
                {
                    CheckListGroup checkList = new CheckListGroup();

                    if (id == 0)
                    {
                        context.CheckListGroup.Add(checkList);
                    }

                    if (id > 0)
                    {
                        checkList = context.CheckListGroup.FirstOrDefault(o => o.CheckListGroupID == id);

                        if (checkList == null)
                        {
                            notification = new Notification {
                                Type = NotificationType.Error, Message = "Can't Find Data"
                            };
                            return(false);
                        }
                    }

                    this.converter.DTO2DB_CheckListGroup(checkListDTO, ref checkList);
                    context.SaveChanges();

                    dtoItem = this.GetData(checkList.CheckListGroupID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
コード例 #3
0
 public void DTO2DB_CheckListGroup(DTO.CheckListGroupDTO dto, ref CheckListGroup db)
 {
     AutoMapper.Mapper.Map <DTO.CheckListGroupDTO, CheckListGroup>(dto, db);
 }