private void SendToEmailNotification(SeatCushionMngEntities context, string emailSubject, string emailBody) { try { string sendToEmail = string.Empty; List <string> emailAddresses = new List <string>(); // My(AVT)[20] and Thanh(AVT)[74]. emailAddresses = context.EmployeeMng_Employee_View.Where(o => o.UserID == 20 || o.UserID == 74).Select(s => s.Email1).ToList(); foreach (var emailAddress in emailAddresses) { if (!string.IsNullOrEmpty(sendToEmail)) { sendToEmail += "; "; } sendToEmail += emailAddress; } List <int> listUser = new List <int>(); listUser.Add(20); listUser.Add(74); foreach (var item in listUser) { // add to NotificationMessage table NotificationMessage notification = new NotificationMessage(); notification.UserID = item; notification.NotificationMessageTag = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PRODUCTDEVELOPMENT; notification.NotificationMessageTitle = emailSubject; notification.NotificationMessageContent = emailBody; context.NotificationMessage.Add(notification); } // Create data EmailNotificationMessage. EmailNotificationMessage emailNotificationMessage = new EmailNotificationMessage(); emailNotificationMessage.EmailSubject = emailSubject; emailNotificationMessage.EmailBody = emailBody; emailNotificationMessage.SendTo = sendToEmail; context.EmailNotificationMessage.Add(emailNotificationMessage); context.SaveChanges(); } catch (Exception ex) { throw; } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SeatCushionMngEntities context = CreateContext()) { SeatCushion dbItem = context.SeatCushion.FirstOrDefault(o => o.SeatCushionID == id); if (dbItem == null) { notification.Message = "Back cushion not found!"; return(false); } else { var item = context.SeatCushionMng_SeatCushionCheck_View.Where(o => o.SeatCushionID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't delete because it used in item other!"); } context.SeatCushion.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool UpdateData(int id, ref object dtoItem, int iRequesterID, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.SeatCushion dtoSeatCushion = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SeatCushion>(); try { using (SeatCushionMngEntities context = CreateContext()) { SeatCushion dbItem = null; if (id == 0) { dtoSeatCushion.CreatedBy = iRequesterID; dbItem = new SeatCushion(); context.SeatCushion.Add(dbItem); } else { var item = context.SeatCushionMng_SeatCushionCheck_View.Where(o => o.SeatCushionID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't update because it used in item other!"); } dtoSeatCushion.UpdatedBy = iRequesterID; dbItem = context.SeatCushion.FirstOrDefault(o => o.SeatCushionID == id); } if (dbItem == null) { notification.Message = "Back cushion not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoSeatCushion.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoSeatCushion, ref dbItem); // processing image if (dtoSeatCushion.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoSeatCushion.ImageFile_NewFile, dtoSeatCushion.ImageFile); } if (id <= 0) { // generate code using (DbContextTransaction scope = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM SeatCushion WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.SeatCushionMng_function_GenerateCode().FirstOrDefault(); if (newCode != "*") { dbItem.SeatCushionUD = 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 SEAT CUSHION]" : "TASK REQUEST [UPDATE SEAT CUSHION]"; string emailBody = string.Empty; if (!IsNullPropertiesSeatCushion(dbItem, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(dbItem.SeatCushionID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }