Ejemplo n.º 1
0
        private void SendToEmailNotification(CushionColorMngEntities context, string emailSubject, string emailBody)
        {
            try
            {
                string sendToEmail = string.Empty;

                // My(AVT)[20] and Thanh(AVT)[74]
                foreach (var empObj in context.EmployeeMng_Employee_View.Where(o => !string.IsNullOrEmpty(o.Email1) && (o.UserID == 20 || o.UserID == 74 || o.UserID == 1)).ToList())
                {
                    if (!string.IsNullOrEmpty(sendToEmail))
                    {
                        sendToEmail += "; ";
                    }

                    sendToEmail += empObj.Email1;

                    // add to NotificationMessage table
                    context.NotificationMessage.Add(new NotificationMessage {
                        UserID = empObj.UserID,
                        NotificationMessageTag     = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PRODUCTION,
                        NotificationMessageTitle   = emailSubject,
                        NotificationMessageContent = emailBody
                    });
                }

                // Create data EmailNotificationMessage.
                EmailNotificationMessage emailNotificationMessage = new EmailNotificationMessage();
                emailNotificationMessage.EmailSubject = emailSubject;
                emailNotificationMessage.EmailBody    = emailBody;
                emailNotificationMessage.SendTo       = sendToEmail;

                context.EmailNotificationMessage.Add(emailNotificationMessage);
                context.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Ejemplo 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);
            }
        }