示例#1
0
        public ActionResult Create([Bind(Include = "Id,Name,ContactNo,FacebookId,EmailId,CNIC,InstituteId,StatusId,CreatedAt,Address,CityOfResidence,Degree,PreviousExperiance,AmbassadorCategoryId,Hostelite,Why,ExpectationsFromSEE")] Ambassador ambassador)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var obj = db.Ambassadors.FirstOrDefault(s => s.EmailId == ambassador.EmailId || s.ContactNo == ambassador.ContactNo);
                    if (obj != null)
                    {
                        ViewBag.ErrorMessage = "Email Or Phone No. Already Exists!";
                        ViewBag.InstituteId  = new SelectList(db.Institutes, "Id", "Institute1");

                        ViewBag.AmbassadorCategoryId = new SelectList(db.AmbassadorCategories, "Id", "Category", ambassador.AmbassadorCategoryId);
                        ViewBag.StatusId             = new SelectList(db.RequestStatus, "Id", "Status", ambassador.StatusId);
                        return(View(ambassador));
                    }
                    try
                    {
                        ambassador.ExpectationsFromSEE = Request.Form["ExpectationsFromSEE"];
                        ambassador.CreatedAt           = DateTime.Now;
                        ambassador.StatusId            = 1;
                        db.Ambassadors.Add(ambassador);
                        db.SaveChanges();
                        string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                        string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                        return(RedirectToAction("SubmissionResponce", "Home", new { status = "You are successfully registerd for Ambassador with your crdentials,Team SEE Lahore will soon respond you through Email.Stay Connected for Bigest Event of Lahore, See Lahore 2018", url = controllerName + "/" + actionName }));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        string message = "";
                        foreach (var validationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                message = message + validationError.PropertyName + "  " + validationError.ErrorMessage + "\n\n";
                            }
                        }

                        HomeController.EntityinfoMessage(ambassador.Name + ": " + message);
                        HomeController.EntitywriteErrorLog(ex);
                        string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                        string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                        return(RedirectToAction("SubmissionResponce", "Home", new { status = "Due to Server overload something went wrong! please try again. Sorry for Inconvenience", url = controllerName + "/" + actionName }));
                    }
                }


                ViewBag.InstituteId = new SelectList(db.Institutes, "Id", "Institute1");

                ViewBag.AmbassadorCategoryId = new SelectList(db.AmbassadorCategories, "Id", "Category", ambassador.AmbassadorCategoryId);
                ViewBag.StatusId             = new SelectList(db.RequestStatus, "Id", "Status", ambassador.StatusId);
                return(View(ambassador));
            }
            catch (Exception ex)
            {
                string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                HomeController.infoMessage(ex.Message);
                HomeController.writeErrorLog(ex);
                return(RedirectToAction("SubmissionResponce", "Home", new { status = "Due to Server overload something went wrong! please try again. Sorry for Inconvenience", url = controllerName + "/" + actionName }));
            }
        }
        public ActionResult Create([Bind(Include = "Id,StallName,StallDetails,Logo,RequestStatusId,CategoryId,CreatedBy,CreatedAt,OwnerName,ContactNo,Email,Address,City,Profession,Institute")] StallRequest stallRequest, HttpPostedFileBase Logo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var obj = db.StallRequests.FirstOrDefault(s => s.Email == stallRequest.Email);
                    if (obj != null)
                    {
                        ViewBag.ErrorMessage    = "Email Already Exists!";
                        ViewBag.CreatedBy       = new SelectList(db.AspNetUsers, "Id", "Email", stallRequest.CreatedBy);
                        ViewBag.InstituteId     = new SelectList(db.Institutes, "Id", "Institute1");
                        ViewBag.RequestStatusId = new SelectList(db.RequestStatus, "Id", "Status", stallRequest.RequestStatusId);
                        ViewBag.CategoryId      = new SelectList(db.StallCategories, "Id", "StallType", stallRequest.CategoryId);
                        return(View(stallRequest));
                    }
                    if (Logo != null && Logo.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(Logo.FileName);
                        var path     = Path.Combine(Server.MapPath("~/UploadedImages/"), fileName);
                        Logo.SaveAs(path);
                        stallRequest.Logo = fileName;
                    }
                    try
                    {
                        stallRequest.RequestStatusId = 1;
                        stallRequest.CreatedAt       = DateTime.Now;
                        stallRequest.CreatedBy       = User.Identity.GetUserId();
                        db.StallRequests.Add(stallRequest);
                        db.SaveChanges();
                        string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                        string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                        return(RedirectToAction("SubmissionResponce", "Home", new { status = "Your stall proposal is successfully registerd with your crdentials,Team SEE Lahore will soon respond you through Email.Stay Connected for Bigest Event of Lahore,See Lahore 2018", url = controllerName + "/" + actionName }));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        string message = "";
                        foreach (var validationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                message = message + validationError.PropertyName + "  " + validationError.ErrorMessage + "\n\n";
                            }
                        }

                        HomeController.EntityinfoMessage(stallRequest.OwnerName + ": " + message);
                        HomeController.EntitywriteErrorLog(ex);
                        string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                        string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                        return(RedirectToAction("SubmissionResponce", "Home", new { status = "Due to Server overload something went wrong! please try again. Sorry for Inconvenience", url = controllerName + "/" + actionName }));
                    }
                }
                ViewBag.CreatedBy       = new SelectList(db.AspNetUsers, "Id", "Email", stallRequest.CreatedBy);
                ViewBag.InstituteId     = new SelectList(db.Institutes, "Id", "Institute1");
                ViewBag.RequestStatusId = new SelectList(db.RequestStatus, "Id", "Status", stallRequest.RequestStatusId);
                ViewBag.CategoryId      = new SelectList(db.StallCategories, "Id", "StallType", stallRequest.CategoryId);
                return(View(stallRequest));
            }
            catch (Exception ex)
            {
                string actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                HomeController.infoMessage(ex.Message);
                HomeController.writeErrorLog(ex);
                return(RedirectToAction("SubmissionResponce", "Home", new { status = "Due to Server overload something went wrong! please try again. Sorry for Inconvenience", url = controllerName + "/" + actionName }));
            }
        }