Exemplo n.º 1
0
        public override DTO.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data = new DTO.CushionColor();
            data.Data.CushionColorProductGroups = new List <DTO.CushionColorProductGroup>();
            data.Data.CushionColorTestReports   = new List <DTO.CushionColorTestReport>();
            data.Seasons                 = new List <DTO.Season>();
            data.CushionTypes            = new List <DTO.CushionType>();
            data.Data.CushionTestingDTOs = new List <DTO.CushionTestingDTO>();

            //try to get data
            try
            {
                using (CushionColorMngEntities context = CreateContext())
                {
                    if (id == 0)
                    {
                        data.Data.ImageFile_DisplayUrl = FrameworkSetting.Setting.ThumbnailUrl + "no-image.jpg";

                        int index = -1;
                        foreach (DTO.ProductGroup dtoGroup in GetProductGroup())
                        {
                            data.Data.CushionColorProductGroups.Add(new DTO.CushionColorProductGroup()
                            {
                                CushionColorProductGroupID = index, ProductGroupID = dtoGroup.ProductGroupID, ProductGroupNM = dtoGroup.ProductGroupNM, IsEnabled = false
                            });
                            index--;
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_CushionColor(context.CushionColorMng_CushionColor_View.Include("CushionColorMng_CushionColorProductGroup_View").FirstOrDefault(o => o.CushionColorID == id));
                    }
                    data.Seasons      = GetSeason().ToList();
                    data.CushionTypes = GetCushionType().ToList();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Exemplo n.º 2
0
 public IEnumerable <DTO.CushionType> GetCushionType()
 {
     //try to get data
     try
     {
         using (CushionColorMngEntities context = CreateContext())
         {
             return(converter.DB2DTO_CushionType(context.SupportMng_CushionType_View.ToList()));
         }
     }
     catch
     {
         return(new List <DTO.CushionType>());
     }
 }
Exemplo n.º 3
0
 public IEnumerable <DTO.ProductGroup> GetProductGroup()
 {
     //try to get data
     try
     {
         using (CushionColorMngEntities context = CreateContext())
         {
             return(converter.DB2DTO_ProductGroup(context.SupportMng_ProductGroup_View.ToList()));
         }
     }
     catch
     {
         return(new List <DTO.ProductGroup>());
     }
 }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data   = new List <DTO.CushionColorSearchResult>();
            totalRows   = 0;
            _TempFolder = filters["tempFoder"].ToString();

            string CushionColorUD = null;
            string CushionColorNM = null;
            string Season         = null;
            bool?  IsStandard     = null;
            bool?  IsEnabled      = null;
            int?   ProductGroupID = null;
            int?   CushionTypeID  = null;

            if (filters.ContainsKey("CushionColorUD") && !string.IsNullOrEmpty(filters["CushionColorUD"].ToString()))
            {
                CushionColorUD = filters["CushionColorUD"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("CushionColorNM") && !string.IsNullOrEmpty(filters["CushionColorNM"].ToString()))
            {
                CushionColorNM = filters["CushionColorNM"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
            {
                Season = filters["Season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("IsStandard") && filters["IsStandard"] != null && !string.IsNullOrEmpty(filters["IsStandard"].ToString()))
            {
                IsStandard = (filters["IsStandard"].ToString() == "true") ? true : false;
            }
            if (filters.ContainsKey("IsEnabled") && filters["IsEnabled"] != null && !string.IsNullOrEmpty(filters["IsEnabled"].ToString()))
            {
                IsEnabled = (filters["IsEnabled"].ToString() == "true") ? true : false;
            }
            if (filters.ContainsKey("ProductGroupID") && filters["ProductGroupID"] != null && !string.IsNullOrEmpty(filters["ProductGroupID"].ToString()))
            {
                ProductGroupID = Convert.ToInt32(filters["ProductGroupID"]);
            }
            if (filters.ContainsKey("CushionTypeID") && filters["CushionTypeID"] != null && !string.IsNullOrEmpty(filters["CushionTypeID"].ToString()))
            {
                CushionTypeID = Convert.ToInt32(filters["CushionTypeID"]);
            }

            //try to get data
            try
            {
                using (CushionColorMngEntities context = CreateContext())
                {
                    totalRows = context.CushionColorMng_function_SearchCushionColor(CushionColorUD, CushionColorNM, Season, IsStandard, IsEnabled, ProductGroupID, CushionTypeID, orderBy, orderDirection).Count();
                    var result = context.CushionColorMng_function_SearchCushionColor(CushionColorUD, CushionColorNM, Season, IsStandard, IsEnabled, ProductGroupID, CushionTypeID, orderBy, orderDirection);
                    data.Data = converter.DB2DTO_CushionColorSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }