Esempio n. 1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialMngEntities context = CreateContext())
                {
                    Material dbItem = context.Material.FirstOrDefault(o => o.MaterialID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Material not found!");
                    }

                    // check if ok to delete
                    ////

                    // everything ok, delete the task
                    context.Material.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.Material dtoMaterial = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Material>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialMngEntities context = CreateContext())
                {
                    Material dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Material();
                        context.Material.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Material.FirstOrDefault(o => o.MaterialID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Material not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB(dtoMaterial, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);
                        context.SaveChanges();
                        dtoItem = GetData(dbItem.MaterialID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }