public tblGroupDetail GetGroupDetails(int GroupId)
        {
            tblGroupDetail objGroupDetail = new tblGroupDetail();

            using (var context = new CommonDBContext())
            {
                objGroupDetail = context.tblGroupDetails.Where(x => x.GroupId == GroupId).FirstOrDefault();
            }
            return(objGroupDetail);
        }
        public GroupConfig GetGroupConfig(tblGroupDetail objGroupDetails)
        {
            GroupConfig objGroupConfig = new GroupConfig();

            using (var context = new CommonDBContext())
            {
                objGroupConfig.CityName           = context.tblCities.Where(x => x.CityId == objGroupDetails.City).Select(y => y.CityName).FirstOrDefault();
                objGroupConfig.CategoryName       = context.tblCategories.Where(x => x.CategoryId == objGroupDetails.RetailCategory).Select(y => y.CategoryName).FirstOrDefault();
                objGroupConfig.BillingPartnerName = context.tblBillingPartners.Where(x => x.BillingPartnerId == objGroupDetails.BillingPartner).Select(y => y.BillingPartnerName).FirstOrDefault();
                objGroupConfig.BillingSystemName  = context.BOTS_TblBillingPartnerProduct.Where(x => x.BillingPartnerProductId == objGroupDetails.BillingProduct).Select(y => y.BillingPartnerProductName).FirstOrDefault();
                objGroupConfig.SourceByName       = context.tblSourcedBies.Where(x => x.SourcedbyId == objGroupDetails.SourcedBy).Select(y => y.SourcedbyName).FirstOrDefault();
                objGroupConfig.CSAssignedName     = context.tblRMAssigneds.Where(x => x.RMAssignedId == objGroupDetails.RMAssigned).Select(y => y.RMAssignedName).FirstOrDefault();
            }
            return(objGroupConfig);
        }
예제 #3
0
        public ActionResult AddNewCustomer(string ProductType, string groupId)
        {
            CustomerViewModel objCustomerViewModel = new CustomerViewModel();

            try
            {
                tblGroupDetail    objGroupDetail    = new tblGroupDetail();
                tblModulesPayment objModulesPayment = new tblModulesPayment();

                if (!string.IsNullOrEmpty(groupId))
                {
                    CommonFunctions common = new CommonFunctions();
                    groupId        = common.DecryptString(groupId);
                    objGroupDetail = CR.GetGroupDetails(Convert.ToInt32(groupId));
                    var LogoURL = System.Configuration.ConfigurationManager.AppSettings["LogoURL"];
                    objGroupDetail.Logo = LogoURL + objGroupDetail.Logo;

                    objModulesPayment         = CR.GetModulesAndPayments(Convert.ToInt32(groupId));
                    objModulesPayment.GroupId = Convert.ToInt32(groupId);
                }
                if (!string.IsNullOrEmpty(ProductType))
                {
                    objGroupDetail.ProductType = Convert.ToInt32(ProductType);
                }
                objCustomerViewModel.objGroupData      = objGroupDetail;
                objCustomerViewModel.objModulesPayment = objModulesPayment;

                objCustomerViewModel.lstRetailCategory = CR.GetRetailCategory();
                objCustomerViewModel.lstCity           = CR.GetCity();
                objCustomerViewModel.lstSourcedBy      = CR.GetSourcedBy();
                objCustomerViewModel.lstRMAssigned     = CR.GetRMAssigned();
                objCustomerViewModel.lstBillingPartner = CR.GetBillingPartner();
            }
            catch (Exception ex)
            {
                newexception.AddException(ex, groupId);
            }
            return(View(objCustomerViewModel));
        }
        public int AddGroupDetails(tblGroupDetail objGroupDetails)
        {
            int GroupId = 0;

            using (var context = new CommonDBContext())
            {
                using (DbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(objGroupDetails.OtherBillingPartner))
                        {
                            tblBillingPartner objBillingPartner = new tblBillingPartner();
                            objBillingPartner.BillingPartnerName = objGroupDetails.OtherBillingPartner;
                            context.tblBillingPartners.AddOrUpdate(objBillingPartner);
                            context.SaveChanges();
                            objGroupDetails.BillingPartner = objBillingPartner.BillingPartnerId;
                        }
                        if (!string.IsNullOrEmpty(objGroupDetails.OtherCity))
                        {
                            tblCity objCity = new tblCity();
                            objCity.CityName = objGroupDetails.OtherCity;
                            context.tblCities.AddOrUpdate(objCity);
                            context.SaveChanges();
                            objGroupDetails.City = objCity.CityId;
                        }
                        if (!string.IsNullOrEmpty(objGroupDetails.OtherRetailCategory))
                        {
                            tblCategory objCategory = new tblCategory();
                            objCategory.CategoryName = objGroupDetails.OtherRetailCategory;
                            context.tblCategories.AddOrUpdate(objCategory);
                            context.SaveChanges();
                            objGroupDetails.RetailCategory = objCategory.CategoryId;
                        }
                        if (!string.IsNullOrEmpty(objGroupDetails.OtherRMAssigned))
                        {
                            tblRMAssigned objRMAssigned = new tblRMAssigned();
                            objRMAssigned.RMAssignedName = objGroupDetails.OtherRMAssigned;
                            context.tblRMAssigneds.AddOrUpdate(objRMAssigned);
                            context.SaveChanges();
                            objGroupDetails.RMAssigned = objRMAssigned.RMAssignedId;
                        }
                        if (!string.IsNullOrEmpty(objGroupDetails.OtherSourcedBy))
                        {
                            tblSourcedBy objSourcedBy = new tblSourcedBy();
                            objSourcedBy.SourcedbyName = objGroupDetails.OtherSourcedBy;
                            context.tblSourcedBies.AddOrUpdate(objSourcedBy);
                            context.SaveChanges();
                            objGroupDetails.SourcedBy = objSourcedBy.SourcedbyId;
                        }

                        if (!string.IsNullOrEmpty(objGroupDetails.Logo))
                        {
                            //Upload Logo Image
                            var          profilePhysicalURL = System.Configuration.ConfigurationManager.AppSettings["LogoPhysicalURL"];
                            string       filePhysicalPath   = System.IO.Path.Combine(profilePhysicalURL + "\\");
                            string       base64String       = Convert.ToString(objGroupDetails.LogoBase64);
                            byte[]       newBytes           = Convert.FromBase64String(base64String);
                            MemoryStream ms = new MemoryStream(newBytes, 0, newBytes.Length);
                            ms.Write(newBytes, 0, newBytes.Length);
                            var        fileName = Convert.ToString(objGroupDetails.GroupId + ".jpg");
                            FileStream fileNew  = new FileStream(filePhysicalPath + "\\" + fileName, FileMode.Create, FileAccess.Write);
                            ms.WriteTo(fileNew);
                            fileNew.Close();
                            ms.Close();
                            objGroupDetails.Logo = fileName;
                        }

                        string grpId = Convert.ToString(objGroupDetails.GroupId);
                        //Check Customer DB exist
                        var DBDetails = context.DatabaseDetails.Where(x => x.GroupId == grpId).FirstOrDefault();
                        if (DBDetails == null)
                        {
                            //Create Customer DB And Add Entry to DatabaseDetails Table
                            var LastGroupId = context.tblGroupDetails.OrderByDescending(x => x.GroupId).Take(1).Select(y => y.GroupId).FirstOrDefault();
                            objGroupDetails.GroupId = LastGroupId + 1;
                        }

                        context.tblGroupDetails.AddOrUpdate(objGroupDetails);
                        context.SaveChanges();

                        transaction.Commit();
                        GroupId = objGroupDetails.GroupId;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }

            return(GroupId);
        }