Exemple #1
0
        public override bool DeleteData(int id, out Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            try
            {
                using (var context = this.CreateContext())
                {
                    ProductionTeam productionTeam = context.ProductionTeam.FirstOrDefault(o => o.ProductionTeamID == id);

                    if (productionTeam == null)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Can not found data!";

                        return(false);
                    }

                    context.ProductionTeam.Remove(productionTeam);
                    context.SaveChanges();
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Exemple #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.ProductionTeamDto productionTeamDto = ((JObject)dtoItem).ToObject <DTO.ProductionTeamDto>();
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = this.CreateContext())
                {
                    ProductionTeam productionTeam = new ProductionTeam();

                    if (id == 0)
                    {
                        context.ProductionTeam.Add(productionTeam);
                    }

                    if (id > 0)
                    {
                        productionTeam = context.ProductionTeam.FirstOrDefault(o => o.ProductionTeamID == id);

                        if (productionTeam == null)
                        {
                            notification.Message = "Can not found data!";
                            return(false);
                        }
                    }

                    this.converter.DTO2DB_ProductionTeam(productionTeamDto, ref productionTeam);
                    productionTeam.UpdatedBy   = userId;
                    productionTeam.UpdatedDate = System.DateTime.Now;
                    productionTeam.CompanyID   = fwFactory.GetCompanyID(userId);
                    context.SaveChanges();
                    dtoItem = this.GetData(productionTeam.ProductionTeamID, out notification);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Exemple #3
0
 public void DTO2DB_ProductionTeam(DTO.ProductionTeamDto dto, ref ProductionTeam db)
 {
     AutoMapper.Mapper.Map <DTO.ProductionTeamDto, ProductionTeam>(dto, db);
 }