Exemplo n.º 1
0
        public override bool Approve(int id, ref DTO.BookingMng.Booking dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                if (string.IsNullOrEmpty(dtoItem.ShipedDate))
                {
                    throw new Exception("You need fill-in shipped date before confirm");
                }

                // only update the current data if the status is different than CONFIRMED
                if (!dtoItem.IsConfirmed.HasValue || !dtoItem.IsConfirmed.Value)
                {
                    // update current data
                    if (!UpdateData(id, ref dtoItem, out notification))
                    {
                        throw new Exception(notification.Message);
                    }
                }
                else
                {
                    throw new Exception(DALBase.Helper.TEXT_CONFIRMED_CONFLICT);
                }

                using (BookingMngEntities context = CreateContext())
                {
                    Booking dbItem = context.Booking.FirstOrDefault(o => o.BookingID == id);
                    if (dbItem != null)
                    {
                        dbItem.IsConfirmed   = true;
                        dbItem.ConfirmedBy   = dtoItem.UpdatedBy;
                        dbItem.ConfirmedDate = DateTime.Now;
                        context.SaveChanges();

                        //dtoItem = GetData(id, out notification).Data;
                        return(true);
                    }
                    else
                    {
                        throw new Exception("Booking No: " + dtoItem.BookingUD + " not found!");
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
        public override bool Reset(int id, ref DTO.BookingMng.Booking dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                if (dtoItem.IsConfirmed.HasValue && dtoItem.IsConfirmed.Value)
                {
                    using (BookingMngEntities context = CreateContext())
                    {
                        Booking dbItem = context.Booking.FirstOrDefault(o => o.BookingID == id);
                        if (dbItem != null)
                        {
                            dbItem.IsConfirmed   = false;
                            dbItem.ConfirmedBy   = null;
                            dbItem.ConfirmedDate = null;
                            dbItem.UpdatedBy     = dtoItem.UpdatedBy;
                            dbItem.UpdatedDate   = DateTime.Now;
                            context.SaveChanges();
                            //dtoItem = GetData(id, out notification).Data;

                            return(true);
                        }
                        else
                        {
                            throw new Exception("Booking No: " + dtoItem.BookingUD + " not found!");
                        }
                    }
                }
                else
                {
                    throw new Exception("Booking No: " + dtoItem.BookingUD + " is not confirmed, no need to reset!");
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
Exemplo n.º 3
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (BookingMngEntities context = CreateContext())
         {
             Booking dbItem = context.Booking.FirstOrDefault(o => o.BookingID == id);
             if (dbItem == null)
             {
                 throw new Exception("Booking No: " + dbItem.BookingUD + " not found!");
             }
             else
             {
                 if (!dbItem.IsConfirmed.HasValue || !dbItem.IsConfirmed.Value)
                 {
                     context.Booking.Remove(dbItem);
                     context.SaveChanges();
                     return(true);
                 }
                 else
                 {
                     throw new Exception("Can not delete the approved booking");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
         {
             notification.DetailMessage.Add(ex.InnerException.Message);
         }
         return(false);
     }
 }
Exemplo n.º 4
0
        public override bool UpdateData(int id, ref DTO.BookingMng.Booking dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (BookingMngEntities context = CreateContext())
                {
                    Booking dbItem = null;
                    if (id == 0)
                    {
                        dbItem             = new Booking();
                        dbItem.CreatedBy   = dtoItem.UpdatedBy;
                        dbItem.CreatedDate = DateTime.Now;
                        context.Booking.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Booking.FirstOrDefault(o => o.BookingID == id);
                    }

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

                        // check if status = CONFIRMED
                        if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONFIRMED_CONFLICT);
                        }

                        //file processing
                        Library.FileHelper.FileManager fileMng = new Library.FileHelper.FileManager(FrameworkSetting.Setting.AbsoluteFileFolder);
                        string fileNeedDeleted          = string.Empty;
                        string thumbnailFileNeedDeleted = string.Empty;

                        if (dtoItem.BLFileHasChange)
                        {
                            //check to delete file does not exist in database
                            if (!string.IsNullOrEmpty(dtoItem.BLFile))
                            {
                                fwFactory.GetDBFileLocation(dtoItem.BLFile, out fileNeedDeleted, out thumbnailFileNeedDeleted);
                                if (!string.IsNullOrEmpty(fileNeedDeleted))
                                {
                                    try
                                    {
                                        fileMng.DeleteFile(fileNeedDeleted);
                                    }
                                    catch { }
                                }
                            }
                            if (string.IsNullOrEmpty(dtoItem.NewBLFile))
                            {
                                // remove file registration in File table
                                fwFactory.RemoveFile(dtoItem.BLFile);
                                // reset file in table Contract
                                dtoItem.BLFile = string.Empty;
                            }
                            else
                            {
                                string outDBFileLocation = "";
                                string outFileFullPath   = "";
                                string outFilePointer    = "";
                                // copy new file
                                fileMng.StoreFile(_tempFolder + dtoItem.NewBLFile, out outDBFileLocation, out outFileFullPath);

                                if (File.Exists(outFileFullPath))
                                {
                                    FileInfo info = new FileInfo(outFileFullPath);
                                    // insert/update file registration in database
                                    fwFactory.UpdateFile(dtoItem.BLFile, dtoItem.NewBLFile, outDBFileLocation, info.Extension, "", (int)info.Length, out outFilePointer);
                                    // set file database pointer
                                    dtoItem.BLFile = outFilePointer;
                                }
                            }
                        }
                        converter.DTO2DB(dtoItem, ref dbItem);
                        dbItem.UpdatedBy   = dtoItem.UpdatedBy;
                        dbItem.UpdatedDate = DateTime.Now;

                        // remove orphans
                        context.BookingDetail.Local.Where(o => o.Booking == null).ToList().ForEach(o => context.BookingDetail.Remove(o));
                        context.SaveChanges();

                        // generate booking code
                        if (id == 0)
                        {
                            //dbItem.BookingUD = supportFactory.GetSupplier().FirstOrDefault(o => o.SupplierID == dbItem.SupplierID).SupplierUD + "/" + dtoItem.ClientUD + "/" + dtoItem.Season.Substring(5, 4);
                            //using (DbContextTransaction scope = context.Database.BeginTransaction())
                            //{
                            //    context.Database.ExecuteSqlCommand("SELECT TOP 1 * FROM Booking WITH (TABLOCKX, HOLDLOCK)");
                            //    try
                            //    {
                            //        dbItem.BookingUD = context.Booking.Count(o => o.SupplierID == dbItem.SupplierID && o.Season == dbItem.Season).ToString().AddPrefix("0", 4) + "/" + dbItem.BookingUD;
                            //        context.SaveChanges();
                            //    }
                            //    catch { }
                            //    finally
                            //    {
                            //        scope.Commit();
                            //    }
                            //}
                            context.BookingMng_function_UpdateBookingRef(dbItem.BookingID);
                        }
                        dtoItem = GetData(dbItem.BookingID, 0, 0, "", out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }