Esempio n. 1
0
        public override bool UpdateData(int id, ref DTO.FactoryMng.Factory dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryMngEntities context = CreateContext())
                {
                    Factory dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Factory();
                        context.Factory.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Factory.FirstOrDefault(o => o.FactoryID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        converter.DTO2BD_Material(dtoItem, ref dbItem);
                        context.SaveChanges();

                        // run sync
                        if (id == 0)
                        {
                            context.SyncFactoryAndUserAccessFactory();
                            context.SaveChanges();
                        }

                        dtoItem = GetData(dbItem.FactoryID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryMngEntities context = CreateContext())
                {
                    Factory dbItem = context.Factory.FirstOrDefault(o => o.FactoryID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory not found!";
                        return(false);
                    }
                    else
                    {
                        context.Factory.Remove(dbItem);
                        context.SaveChanges();

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