Exemple #1
0
        public ActionResult SaveAccounts(string pAccountCode, string pCompanyName, string pCompanyPhone, string pCompanyExt, string pCompanyFax, bool? pDryOnly, bool? pFreezer,
        bool? pFood, string pAccountType1, int? pPrimaryAcctCode, int? pNuberOfStores, string pAccountType2, string pTerritory, string pDivision, int? pCSNDirID,
            string pAddress1, string pAddress2, string pCity, string pState, string pZip, string pCountry, string pShipToName, string pShipToAddress1, string pShipToAddress2,
            string pShipToCity, string pShipToState, string pShipZip, bool? pHotProgram, string pRollerGrid, string pGasBand, string pPrimaryDistributor, string pShipToCountry)
        {
            int sResult = 0;
            string vResult = string.Empty;
            string vMessage = string.Empty;
            int vAccountCode = 0;
            dynamic values = new TblAccountList();
            values.Company = pCompanyName;
            values.CompanyPhone = pCompanyPhone;
            values.CompanyExt = pCompanyExt;
            values.CompanyFax = pCompanyFax;
            values.DryOnly = pDryOnly;
            values.Freezer = pFreezer;
            values.Food = pFood;
            values.CustType1 = pAccountType1;
            values.PrimaryAcctCode = pPrimaryAcctCode;
            values.NumStores = pNuberOfStores;
            values.CustType2 = pAccountType2;
            values.Territory = pTerritory;
            values.Division = pDivision;
            values.CSNDirID = pCSNDirID;
            values.AcctStatusID = "ACTIVE";
            values.Address1 = pAddress1;
            values.Address2 = pAddress2;
            values.City = pCity;
            values.State = pState;
            values.Zip = pZip;
            values.Country = pCountry;
            values.ShipToName = pShipToName;
            values.ShipToAddress1 = pShipToAddress1;
            values.ShipToAddress2 = pShipToAddress2;
            values.ShipToCity = pShipToCity;
            values.ShipToState = pShipToState;
            values.ShipToMailCode = pShipZip;
            values.ShipToCountry = pShipToCountry;
            values.RollerGrid = pRollerGrid;
            values.FoodProgram = pHotProgram;
            values.GasBrand = pGasBand;
            values.PrimaryAcctCode = pPrimaryAcctCode;
            using (var db = new CSN.DAL.CSNDBEntities())
            {



                try
                {
                    if (pAccountCode == "")
                    {
                        var User = db.TblAccountLists.OrderByDescending(u => u.AccountCode).FirstOrDefault();
                        if (User == null)
                        {
                            values.AccountCode = 1;
                        }
                        else
                        {
                            values.AccountCode = User.AccountCode + 1;
                        }

                        db.TblAccountLists.Add(values);
                        sResult = db.SaveChanges();
                    }
                    else
                    {
                        values.AccountCode = Convert.ToInt32(pAccountCode);
                        db.Entry(values).State = EntityState.Modified;
                        sResult = db.SaveChanges();
                    }
                    if (sResult == 1)
                    {
                        vResult = "S";
                        vMessage = "S";
                        vAccountCode = values.AccountCode;
                    }


                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                }


            }

            ViewBag.AccountCode = vAccountCode;
            return Json(new { Status = vResult, Message = vMessage, AccountCode = vAccountCode });
        }
Exemple #2
0
        public ActionResult DeleteAccount(int AccountCode)
        {
            ViewBag.PageCaption = "Delete Account List";
            int sResult = 0;
            string vResult = string.Empty;
            string vMessage = string.Empty;
            using (var context = new CSN.DAL.CSNDBEntities())
            {
                try
                {


                    var TblContactMastersList = context.TblContactMasters.Where(d => d.AccountCode == AccountCode);
                    if (TblContactMastersList != null)
                    {
                        foreach (var ContactMastersList in TblContactMastersList)
                        {
                            //var BuyersLineCarryList = context.TblBuyersLineCarrys.Where(d => d.ContactID == ContactMastersList.ContactID);
                            //if (BuyersLineCarryList != null)
                            //{
                            //    foreach (TblBuyersLineCarry BuyersLineCarry in BuyersLineCarryList)
                            //    {
                            //        context.TblBuyersLineCarrys.Remove(BuyersLineCarry);
                            //    }
                            //}

                            context.TblContactMasters.Remove(ContactMastersList);
                        }
                    }

                    var TblInitiativeResultsList = context.TblInitiativeResults.Where(d => d.AccountID == AccountCode);
                    if (TblInitiativeResultsList != null)
                    {
                        foreach (var InitiativeResults in TblInitiativeResultsList)
                        {
                            context.TblInitiativeResults.Remove(InitiativeResults);
                        }

                    }



                    var Account = context.TblAccountLists.FirstOrDefault(e => e.AccountCode == AccountCode);
                    context.TblAccountLists.Remove(Account);
                    sResult = context.SaveChanges();
                    vResult = "S";
                    vMessage = "S";
                }
                catch
                {
                    vResult = "error";
                    vMessage = "error";

                }



            }

            return Json(new { Status = vResult, Message = vMessage });
        }