public bool UpdateFile(string fileUD, string friendlyName, string fileLocation, string fileExtension, string thumbnailLocation, int fileSize, out string returnUD) { return(factory.UpdateFile(fileUD, friendlyName, fileLocation, fileExtension, thumbnailLocation, fileSize, out returnUD)); }
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); } }