コード例 #1
0
 public void AddBEAT(LocationBeat BEAT)
 {
     db.LocationBeats.Add(BEAT);
     db.SaveChanges();
 }
コード例 #2
0
        public ActionResult BeatHierarchyAddition()
        {
            List <FileHeadersBeatHierarchy> list = (List <FileHeadersBeatHierarchy>)Session["BeatHierarchy"];
            int?id    = (int?)Session["CompanyID"];
            int newId = id ?? default(int);
            var list1 = list.GroupBy(x => x.NSM);


            foreach (var keyitem in list1)
            {
                foreach (var item in keyitem)
                {
                    NationalSalesManager NSM = new NationalSalesManager
                    {
                        Name             = keyitem.Key,
                        EmailId          = item.NSMEmailId,
                        SecondaryEmailId = item.NSMSecondaryEmailId,
                        Zone             = item.NSMZone,
                        CompanyId        = newId
                    };
                    NSMRepository NSMRepo = new NSMRepository();
                    List <NationalSalesManager> NSMList = NSMRepo.GetNSM(newId);

                    if (!NSMList.Exists(x => x.Name == NSM.Name))
                    {
                        NSMRepo.AddNSM(NSM);
                    }
                    //Insert Regions
                    long NSMPk = db.NationalSalesManagers.Where(x => x.Name == item.NSM).Select(x => x.Id).FirstOrDefault();

                    ZonalSalesManager ZSM = new ZonalSalesManager();
                    ZSM.Name                   = item.ZSM;
                    ZSM.EmailId                = item.ZSMEmailId;
                    ZSM.SecondaryEmailId       = item.ZSMSecondaryEmailId;
                    ZSM.Zone                   = item.ZSMZone;
                    ZSM.NationalSalesManagerId = NSMPk;
                    ZSM.CompanyId              = newId;


                    ZSMRepository            ZSMRepo = new ZSMRepository();
                    List <ZonalSalesManager> ZSMList = ZSMRepo.GetZSM(newId);
                    if (!ZSMList.Exists(x => x.Name == ZSM.Name))
                    {
                        ZSMRepo.AddZSM(ZSM);
                    }

                    long ZSMPk = db.ZonalSalesManagers.Where(x => x.Name == item.ZSM).Select(x => x.Id).FirstOrDefault();

                    RegionalSalesManager RSM = new RegionalSalesManager();
                    RSM.Name                = item.RSM;
                    RSM.EmailId             = item.RSMEmailId;
                    RSM.SecondaryEmailId    = item.RSMSecondaryEmailId;
                    RSM.Zone                = item.RSMZone;
                    RSM.ZonalSalesManagerId = ZSMPk;
                    RSM.CompanyId           = newId;

                    RSMRepository RSMRepo = new RSMRepository();
                    List <RegionalSalesManager> RSMList = RSMRepo.GetRSM(newId);
                    if (!RSMList.Exists(x => x.Name == RSM.Name))
                    {
                        RSMRepo.AddRSM(RSM);
                    }

                    long RSMPk = db.RegionalSalesManagers.Where(x => x.Name == item.RSM).Select(x => x.Id).FirstOrDefault();

                    AreaSalesManager ASM = new AreaSalesManager();
                    ASM.Name                   = item.ASM;
                    ASM.EmailId                = item.ASMEmailId;
                    ASM.SecondaryEmailId       = item.ASMSecondaryEmailId;
                    ASM.Zone                   = item.ASMZone;
                    ASM.RegionalSalesManagerId = RSMPk;
                    ASM.CompanyId              = newId;

                    ASMRepository           ASMRepo = new ASMRepository();
                    List <AreaSalesManager> ASMList = ASMRepo.GetASM(newId);
                    if (!ASMList.Exists(x => x.Name == ASM.Name))
                    {
                        ASMRepo.AddASM(ASM);
                    }

                    long ASMPk = db.ClientEmployees.Where(x => x.Name == item.ASM).Select(x => x.Id).FirstOrDefault();

                    ClientEmployee ESM = new ClientEmployee();
                    ESM.Name             = item.ESM;
                    ESM.EmailId          = item.ESMEmailId;
                    ESM.SecondaryEmailId = item.ESMSecondaryEmailId;
                    //   ESM.Zone = item.ESMZone;
                    ESM.ClientSideId       = item.ESMErpId;
                    ESM.AreaSalesManagerId = ASMPk;
                    ESM.Company            = newId;

                    ESMRepository         ESMRepo = new ESMRepository();
                    List <ClientEmployee> ESMList = ESMRepo.GetESM(newId);
                    if (!ESMList.Exists(x => x.Name == ESM.Name))
                    {
                        ESMRepo.AddESM(ESM);
                    }

                    LocationBeat BEAT = new LocationBeat();
                    BEAT.Name         = item.FinalBeatName;
                    BEAT.ErpId        = item.BeatErpId;
                    BEAT.City         = item.BeatDistrict;
                    BEAT.State        = item.BeatState;
                    BEAT.DivisionZone = item.BeatZone;

                    BEATRepository      BEATRepo = new BEATRepository();
                    List <LocationBeat> BEATList = BEATRepo.GetBEAT(newId);

                    if (!BEATList.Exists(x => x.Name == BEAT.Name))
                    {
                        BEATRepo.AddBEAT(BEAT);
                    }
                    Distributor Distributor = new Distributor();
                    Distributor.Name         = item.DistributorName;
                    Distributor.EmailId      = item.DistributorEmailId;
                    Distributor.ClientSideId = item.DistributorErpId;
                    Distributor.Place        = item.DistributorLocation;

                    DistributorRepository DistributorRepo = new DistributorRepository();
                    List <Distributor>    DIstributorList = DistributorRepo.GetDistributor(newId);

                    if (!DIstributorList.Exists(x => x.Name == Distributor.Name))
                    {
                        DistributorRepo.AddDistributor(Distributor);
                    }

                    DistributorBeatMappingRepository DBMRepo = new DistributorBeatMappingRepository();
                    List <DistributorBeatMapping>    DBMList = DBMRepo.GetDistributorBeatMap(newId);

                    long BeatId        = db.LocationBeats.Where(x => x.Name == item.FinalBeatName).Select(x => x.Id).FirstOrDefault();
                    long DistributorId = db.Distributors.Where(x => x.Name == item.DistributorName).Select(x => x.Id).FirstOrDefault();

                    DistributorBeatMapping DBM = new DistributorBeatMapping();
                    DBM.BeatId        = BeatId;
                    DBM.DistributorId = DistributorId;
                    DBM.CompanyId     = newId;

                    if (!DBMList.Contains(DBM))
                    {
                        DBMRepo.AddDistributorBeatMap(DBM);
                    }
                }
            }
            return(View());
        }