コード例 #1
0
        public bool UpdateBuildingProcessData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.BuildingProcess.ProgressDTO dtoProgress = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.BuildingProcess.ProgressDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProgress dbItem;
                    if (id <= 0)
                    {
                        dbItem = new SampleProgress();
                        context.SampleProgress.Add(dbItem);
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;
                    }
                    else
                    {
                        dbItem = context.SampleProgress.FirstOrDefault(o => o.SampleProgressID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Progress not found!";
                        return(false);
                    }
                    else
                    {
                        // check permission
                        if (userId != dbItem.UpdatedBy)
                        {
                            throw new Exception("Can not edit progress created by other user!");
                        }
                        if ((DateTime.Now - dbItem.UpdatedDate.Value).TotalDays > 1)
                        {
                            throw new Exception("Too late to edit this progress, progress can only be updatable within 2 days from the last update!");
                        }
                        converter.DTO2DB_BuildingProcess(dtoProgress, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\");
                        context.SaveChanges();
                    }

                    dtoItem = converter.DB2DTO_BuildingProcess_Progress(context.Sample3Mng_BuildingProcess_Progress_View
                                                                        .Include("Sample3Mng_BuildingProcess_ProgressImage_View")
                                                                        .FirstOrDefault(o => o.SampleProgressID == dbItem.SampleProgressID));

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #2
0
        public bool DeleteBuildingProcessData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProgress dbItem = context.SampleProgress.FirstOrDefault(o => o.SampleProgressID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Progress not found!");
                    }
                    else
                    {
                        // check permission
                        if (userId != dbItem.UpdatedBy)
                        {
                            throw new Exception("Can not delete progress created by other user!");
                        }
                        if ((DateTime.Now - dbItem.UpdatedDate.Value).TotalDays > 1)
                        {
                            throw new Exception("Too late to delete this progress, remark can only be deleted within 2 days from the last update!");
                        }

                        foreach (SampleProgressImage dbImage in dbItem.SampleProgressImage.ToArray())
                        {
                            if (!string.IsNullOrEmpty(dbImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbImage.FileUD);
                            }
                            context.SampleProgressImage.Remove(dbImage);
                        }
                        context.SampleProgress.Remove(dbItem);
                        context.SaveChanges();
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #3
0
        public bool UpdateProductInfoData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ProductInfo.ProductDTO dtoProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductInfo.ProductDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProduct dbItem;
                    if (id <= 0)
                    {
                        dbItem = new SampleProduct();
                        context.SampleProduct.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Sample Product not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_ProductInfo(dtoProduct, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\");
                        context.SaveChanges();
                    }

                    dtoItem = GetProductInfoData(dbItem.SampleProductID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #4
0
        public bool UpdateItemData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ItemData.ProductDTO dtoProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ItemData.ProductDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sample Product not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_ItemData(dtoProduct, ref dbItem);
                        context.SaveChanges();
                    }

                    dtoItem = GetItemData(dbItem.SampleProductID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #5
0
        public bool UpdateOrderData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.SampleOrderDTO dtoOrder = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SampleOrderDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleOrder dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new SampleOrder();
                        context.SampleOrder.Add(dbItem);
                        dbItem.CreatedBy           = userId;
                        dbItem.CreatedDate         = DateTime.Now;
                        dbItem.SampleOrderStatusID = 1; // pending status
                    }
                    else
                    {
                        dbItem = context.SampleOrder.FirstOrDefault(o => o.SampleOrderID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Sample Order not found!";
                        return(false);
                    }
                    else
                    {
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;
                        converter.DTO2DB_SampleOrder(dtoOrder, ref dbItem);
                        context.SaveChanges();

                        if (id <= 0)
                        {
                            // generate order number
                            using (DbContextTransaction scope = context.Database.BeginTransaction())
                            {
                                context.Database.ExecuteSqlCommand("SELECT * FROM SampleOrder WITH (TABLOCKX, HOLDLOCK)");
                                try
                                {
                                    dbItem.SampleOrderUD = dbItem.SampleOrderID.ToString("D8");
                                    context.SaveChanges();
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                finally
                                {
                                    scope.Commit();
                                }
                            }
                        }
                    }

                    dtoItem = GetOrderData(dbItem.SampleOrderID, 0, string.Empty, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }