Esempio n. 1
0
        public ActionResult Create(OfferModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int GYM_ID = Convert.ToInt32(Session["GYM_ID"]);
                    var Offer  = Mapper.Map <Offer>(model);
                    Offer.GYM_ID = GYM_ID;
                    Offer.Status = true;
                    db.Offers.Add(Offer);
                    db.SaveChanges();

                    new Thread(new ThreadStart(() =>
                    {
                        var Branches = db.Branches.Where(i => i.GYM_ID == GYM_ID).ToList();
                        foreach (var Branche in Branches)
                        {
                            Branch_Wise_Offer Branch_Wise_Offer = new Branch_Wise_Offer();
                            Branch_Wise_Offer.Branch_ID         = Branche.ID;
                            Branch_Wise_Offer.Status            = true;
                            Branch_Wise_Offer.GYM_ID            = GYM_ID;
                            Branch_Wise_Offer.Offer_ID          = Offer.ID;
                            db.Branch_Wise_Offer.Add(Branch_Wise_Offer);
                            db.SaveChanges();
                        }
                    })).Start();
                    TempData["Success"] = "Offer Has Created Successfully.!";
                }
                else
                {
                    TempData["Error"] = "Please Fill All Required Details.!";
                    return(View());
                }
                return(RedirectToAction("Index", "Offer"));
            }

            catch (Exception ex)
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
Esempio n. 2
0
        public ActionResult Create(BranchModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int GYM_ID   = Convert.ToInt32(Session["GYM_ID"]);
                    var Branches = db.Branches.Where(i => i.Name == model.Name && i.GYM_ID == GYM_ID).FirstOrDefault();
                    if (Branches == null)
                    {
                        var Branch = Mapper.Map <Branch>(model);
                        Branch.IS_Active = true;
                        Branch.GYM_ID    = GYM_ID;
                        db.Branches.Add(Branch);
                        db.SaveChanges();

                        new Thread(new ThreadStart(() =>
                        {
                            var Equipments = db.Equipments.Where(i => i.GYM_ID == GYM_ID).ToList();
                            foreach (var Equipment in Equipments)
                            {
                                Branch_Wise_Equipment Branch_Wise_Equipment = new Branch_Wise_Equipment();
                                Branch_Wise_Equipment.Branch_ID             = Branch.ID;
                                Branch_Wise_Equipment.Equipment_ID          = Equipment.ID;
                                Branch_Wise_Equipment.GYM_ID = GYM_ID;
                                Branch_Wise_Equipment.Number = 0;
                                db.Branch_Wise_Equipment.Add(Branch_Wise_Equipment);
                                db.SaveChanges();
                            }

                            var Offers = db.Offers.Where(i => i.GYM_ID == GYM_ID).ToList();
                            foreach (var Offer in Offers)
                            {
                                Branch_Wise_Offer Branch_Wise_Offer = new Branch_Wise_Offer();
                                Branch_Wise_Offer.Branch_ID         = Branch.ID;
                                Branch_Wise_Offer.Offer_ID          = Offer.ID;
                                Branch_Wise_Offer.GYM_ID            = GYM_ID;
                                Branch_Wise_Offer.Status            = false;
                                db.Branch_Wise_Offer.Add(Branch_Wise_Offer);
                                db.SaveChanges();
                            }

                            var Planes = db.Planes.Where(i => i.GYM_ID == GYM_ID).ToList();
                            foreach (var Plane in Planes)
                            {
                                Branch_Wise_Plane Branch_Wise_Plane = new Branch_Wise_Plane();
                                Branch_Wise_Plane.Branch_ID         = Branch.ID;
                                Branch_Wise_Plane.Plane_ID          = Plane.ID;
                                Branch_Wise_Plane.GYM_ID            = GYM_ID;
                                Branch_Wise_Plane.Status            = false;
                                db.Branch_Wise_Plane.Add(Branch_Wise_Plane);
                                db.SaveChanges();
                            }
                        })).Start();
                        TempData["Success"] = "Branch Has Created Suscyfully.!";
                    }
                    else
                    {
                        CityModel    city    = new CityModel();
                        StateModel   state   = new StateModel();
                        CountryModel country = new CountryModel();

                        var Countrie = db.Countries.ToList();
                        ViewBag.Countrie_Name = Countrie;
                        var State = db.States.Where(i => i.Country_ID == model.Country_ID).ToList();
                        ViewBag.State_Name = State;
                        if (state != null)
                        {
                            var Citi = db.Cities.Where(i => i.State_ID == model.State_ID).ToList();
                            ViewBag.City_Name = Citi;
                        }
                        else
                        {
                            var Citi = db.Cities.Where(i => i.State_ID == 0).ToList();
                            ViewBag.City_Name = Citi;
                        }
                        TempData["Error"] = "Branch name is already registered.!";
                        return(View());
                    }
                }
                else
                {
                    CityModel    city    = new CityModel();
                    StateModel   state   = new StateModel();
                    CountryModel country = new CountryModel();

                    var Countrie = db.Countries.ToList();
                    ViewBag.Countrie_Name = Countrie;
                    var State = db.States.Where(i => i.Country_ID == model.Country_ID).ToList();
                    ViewBag.State_Name = State;
                    var Citi = db.Cities.Where(i => i.State_ID == model.State_ID).ToList();
                    ViewBag.City_Name = Citi;
                    TempData["Error"] = "Please Fill All Details.!";
                    return(View());
                }
                return(RedirectToAction("Index", "Branch"));
            }

            catch (Exception ex)
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }