Esempio n. 1
0
        private void SendToEmailNotification(CushionColorMngEntities 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;
            }
        }
Esempio n. 2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (CushionColorMngEntities context = CreateContext())
                {
                    CushionColor dbItem = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "CushionColor not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.CushionColorMng_CushionColorCheck_View.Where(o => o.CushionColorID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.CushionColor.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }