Example #1
0
        public BOTS_TblDealDetails GetDealMasterDetails(string GroupId)
        {
            BOTS_TblDealDetails objData = new BOTS_TblDealDetails();

            using (var context = new CommonDBContext())
            {
                objData = context.BOTS_TblDealDetails.Where(x => x.GroupId == GroupId).FirstOrDefault();
            }
            return(objData);
        }
Example #2
0
        public int AddOnboardingCustomer(BOTS_TblGroupMaster objGroup, List <BOTS_TblRetailMaster> objLstRetail,
                                         BOTS_TblDealDetails objDeal, BOTS_TblPaymentDetails objPayment, List <BOTS_TblInstallmentDetails> objLstInstallment, List <BOTS_TblOutletMaster> objLstOutlet)
        {
            bool status  = false;
            var  GroupId = 0;

            using (var context = new CommonDBContext())
            {
                using (DbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(objGroup.GroupId))
                        {
                            var LastGroupId = context.BOTS_TblGroupMaster.OrderByDescending(x => x.GroupId).Take(1).Select(y => y.GroupId).FirstOrDefault();

                            if (!string.IsNullOrEmpty(LastGroupId))
                            {
                                GroupId = Convert.ToInt32(LastGroupId) + 1;
                            }
                            else
                            {
                                GroupId = 2001;
                            }
                            objGroup.GroupId = Convert.ToString(GroupId);
                        }
                        else
                        {
                            GroupId = Convert.ToInt32(objGroup.GroupId);
                        }

                        var path         = ConfigurationManager.AppSettings["CustomerDocuments"].ToString();
                        var ClientFolder = path + "\\" + GroupId;
                        if (!Directory.Exists(ClientFolder))
                        {
                            System.IO.Directory.CreateDirectory(ClientFolder);
                        }

                        if (objGroup.PANDocumentFile != null)
                        {
                            using (Stream inputStream = objGroup.PANDocumentFile.InputStream)
                            {
                                byte[] data;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    inputStream.CopyTo(ms);
                                    data = ms.ToArray();
                                }
                                System.IO.File.WriteAllBytes(Path.Combine(ClientFolder, objGroup.PANDocumentFile.FileName), data);
                            }
                            objGroup.PANDocument = objGroup.PANDocumentFile.FileName;
                        }
                        if (objGroup.GSTDocumentFile != null)
                        {
                            using (Stream inputStream = objGroup.GSTDocumentFile.InputStream)
                            {
                                byte[] data;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    inputStream.CopyTo(ms);
                                    data = ms.ToArray();
                                }
                                System.IO.File.WriteAllBytes(Path.Combine(ClientFolder, objGroup.GSTDocumentFile.FileName), data);
                            }
                            objGroup.GSTDocument = objGroup.GSTDocumentFile.FileName;
                        }


                        if (objGroup.CustomerStatus == "CSUpdate")
                        {
                            var groupDetails = context.BOTS_TblGroupMaster.Where(x => x.GroupId == objGroup.GroupId).FirstOrDefault();
                            groupDetails.CustomerStatus = "CSUpdate";
                            context.BOTS_TblGroupMaster.AddOrUpdate(groupDetails);
                            context.SaveChanges();

                            foreach (var item in objLstOutlet)
                            {
                                context.BOTS_TblOutletMaster.AddOrUpdate(item);
                                context.SaveChanges();
                            }
                        }
                        else
                        {
                            if (objGroup.Referredby != "1" && objGroup.Referredby != "3" && objGroup.Referredby != "4" && objGroup.Referredby != "6")
                            {
                                if (!string.IsNullOrEmpty(objGroup.ReferredNameNew))
                                {
                                    objGroup.ReferredName = objGroup.ReferredNameNew;
                                }
                            }
                            context.BOTS_TblGroupMaster.AddOrUpdate(objGroup);
                            context.SaveChanges();

                            var lstRetail = context.BOTS_TblRetailMaster.Where(x => x.GroupId == objGroup.GroupId).ToList();
                            foreach (var item in lstRetail)
                            {
                                if (string.IsNullOrEmpty(item.BillingPartner))
                                {
                                    item.BillingPartner = "0";
                                }
                                if (string.IsNullOrEmpty(item.BillingProduct))
                                {
                                    item.BillingProduct = "0";
                                }
                                context.BOTS_TblRetailMaster.Remove(item);
                                context.SaveChanges();
                            }

                            foreach (var item in objLstRetail)
                            {
                                var id           = Convert.ToInt32(item.CategoryId);
                                var categoryName = context.tblCategories.Where(x => x.CategoryId == id).Select(y => y.CategoryName).FirstOrDefault();
                                item.CategoryName = categoryName;
                                item.GroupId      = Convert.ToString(objGroup.GroupId);
                                if (item.BOProduct == "2")
                                {
                                    var BillingPId = context.tblBillingPartners.Where(x => x.BillingPartnerName == "OctaXS").Select(y => y.BillingPartnerId).FirstOrDefault();
                                    item.BillingPartner = Convert.ToString(BillingPId);
                                }
                                context.BOTS_TblRetailMaster.AddOrUpdate(item);
                                context.SaveChanges();
                            }

                            objDeal.GroupId = Convert.ToString(objGroup.GroupId);
                            context.BOTS_TblDealDetails.AddOrUpdate(objDeal);
                            context.SaveChanges();

                            objPayment.GroupId = Convert.ToString(objGroup.GroupId);
                            context.BOTS_TblPaymentDetails.AddOrUpdate(objPayment);
                            context.SaveChanges();

                            var lstInstallments = context.BOTS_TblInstallmentDetails.Where(x => x.GroupId == objGroup.GroupId).ToList();
                            foreach (var item in lstInstallments)
                            {
                                context.BOTS_TblInstallmentDetails.Remove(item);
                                context.SaveChanges();
                            }
                            foreach (var item in objLstInstallment)
                            {
                                item.GroupId = Convert.ToString(objGroup.GroupId);
                                context.BOTS_TblInstallmentDetails.AddOrUpdate(item);
                                context.SaveChanges();
                            }
                        }



                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        newexception.AddException(ex, "OnBoarding");
                        GroupId = 0;
                        //throw ex;
                    }
                }
            }
            return(GroupId);
        }