private bool IsNullPropertiesBackCushion(BackCushion backCushion, ref string emailBody) { bool isNotNull = true; // Set content notification. emailBody += "Back Cushion ID: " + backCushion.BackCushionID; emailBody += Environment.NewLine + "Back Cushion UD: " + backCushion.BackCushionUD; emailBody += Environment.NewLine + "Back Cushion NM: " + backCushion.BackCushionNM; // Season is null or not null. if (string.IsNullOrEmpty(backCushion.Season)) { emailBody += Environment.NewLine + "Season: Current value is null."; isNotNull = false; } else { emailBody += Environment.NewLine + "Season: " + backCushion.Season; } // Image is null or not null. if (string.IsNullOrEmpty(backCushion.ImageFile)) { emailBody += Environment.NewLine + "Image: Current value is null."; isNotNull = false; } else { emailBody += Environment.NewLine + "Image: " + backCushion.ImageFile; } return(isNotNull); }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (BackCushionMngEntities context = CreateContext()) { BackCushion dbItem = context.BackCushion.FirstOrDefault(o => o.BackCushionID == id); if (dbItem == null) { notification.Message = "Back cushion not found!"; return(false); } else { var item = context.BackCushionMng_BackCushionCheck_View.Where(o => o.BackCushionID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't delete because it used in item other!"); } context.BackCushion.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { BackCushionDTO dtoPBackCushion = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <BackCushionDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (BackCushionMngEntities context = CreateContext()) { BackCushion dbItem = null; if (id == 0) { dbItem = new BackCushion(); context.BackCushion.Add(dbItem); dtoPBackCushion.CreatedBy = userId; } else { var item = context.BackCushionMng_BackCushionCheck_View.Where(o => o.BackCushionID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't update because it used in item other!"); } dbItem = context.BackCushion.FirstOrDefault(o => o.BackCushionID == id); dtoPBackCushion.UpdatedBy = userId; } if (dbItem == null) { notification.Message = "Back cushion not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoPBackCushion.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoPBackCushion, ref dbItem); // processing image if (dtoPBackCushion.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoPBackCushion.ImageFile_NewFile, dtoPBackCushion.ImageFile); } if (id <= 0) { // generate code using (DbContextTransaction scope = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM BackCushion WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.BackCushionMng_function_GenerateCode().FirstOrDefault(); if (newCode != "*") { dbItem.BackCushionUD = newCode; } else { throw new Exception("Auto generated code exceed maximum option: [Z]"); } context.SaveChanges(); } catch (Exception ex) { throw ex; } finally { scope.Commit(); } } } else { context.SaveChanges(); } // Handle notification missing information. string emailSubject = (id == 0) ? "TASK REQUEST [CREATE BACK CUSHION]" : "TASK REQUEST [UPDATE BACK CUSHION]"; string emailBody = string.Empty; if (!IsNullPropertiesBackCushion(dbItem, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(dbItem.BackCushionID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }