Exemplo n.º 1
0
        public override bool DeleteData(int id, out Notification notification)
        {
            notification = new Notification {
                Type = NotificationType.Success
            };

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

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

                    Context.TypeOfDefect.Remove(unit);
                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Exemplo n.º 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.TypeOfDefectDTO checkListDTO = ((JObject)dtoItem).ToObject <DTO.TypeOfDefectDTO>();

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

            try
            {
                using (var context = CreateContext())
                {
                    TypeOfDefect typeOfDefect = new TypeOfDefect();

                    if (id == 0)
                    {
                        context.TypeOfDefect.Add(typeOfDefect);
                    }

                    if (id > 0)
                    {
                        typeOfDefect = context.TypeOfDefect.FirstOrDefault(o => o.TypeOfDefectID == id);

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

                    this.converter.DTO2DB_TypeOfDefect(checkListDTO, ref typeOfDefect);
                    context.SaveChanges();

                    dtoItem = this.GetData(typeOfDefect.TypeOfDefectID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Exemplo n.º 3
0
 public void DTO2DB_TypeOfDefect(DTO.TypeOfDefectDTO dto, ref TypeOfDefect db)
 {
     AutoMapper.Mapper.Map <DTO.TypeOfDefectDTO, TypeOfDefect>(dto, db);
 }