Event Admin Controller - B M SOLUTION
  • Event Admin Controller

      // Visitor


    <div class="card-body">

            @using (Html.BeginForm("SaveVisitor", "Admin", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal", @id = "form_sample_2" }))

            {

                <input type="hidden" id="Id" name="Id" value="@Model.Registration.Id" />


                <div class="form-group row">

                    <label for="input-1" class="col-sm-2 col-form-label">

                        Visitor Photo

                        <span class="required"> * </span>

                    </label>

                    <div class="col-sm-3">

                        <div class="input-icon right">

                            <i class="fa"></i>

                            @if (@Model.Registration.Id != Guid.Empty && @Model.Registration.Pic != "")

                            {

                                <img src="@Url.Content(Model.Registration.Pic)" alt="..." id="imgprvw" class="imageresize" style="width: 150px; height: 150px;" />

                            }

                            else

                            {

                                <img src="~/UserImage/2.jpg" id="imgprvw" class="imageresize" style="width: 80px; height: 80px;" />

                            }


                        </div>

                    </div>

                    <div class="col-sm-7">

                        <input type="file" name="fileupload" id="fileupload" onchange=" showimagepreviewnew(this) " />

                    </div>

                </div>

                <div class="form-group mb-3">

                    <label class="form-label" for="fullname">Visitor Name</label>

                    <input class="form-control" id="name" name="name" type="text"  placeholder="Full Name"  value="@Model.Registration.Name">

                </div>

                   <div class="form-group text-start mb-3">

                    <label class="form-label" for="mobile">Email</label>

                       <input class="form-control" type="text" placeholder="email" id="email" name="email" value="@Model.Registration.EmailId">

                </div>

                <div class="form-group text-start mb-3">

                    <label class="form-label" for="mobile">Mobile No</label>

                    <input class="form-control" type="text" placeholder="Mobile" id="mobileno" name="mobileno" value="@Model.Registration.MobileNo">

                </div>

                <div class="form-group text-start mb-3">

                    <label class="form-label" for="password">Password</label>

                    <input class="form-control input-psswd" id="registerPassword" name="registerPassword" type="password" placeholder="Password" value="@Model.Registration.Password">

                </div>

                <div class="form-group mb-3">

                    <label class="form-label" for="job">Job Title</label>

                    @Html.DropDownList("drpjob", (SelectList)ViewBag.job, "Select Work", new { @class = "form-control", @required = "required" })

                  

                </div>


                <div class="form-group mb-3">

                    <label class="form-label" for="address">Address</label>

                    <input class="form-control" id="address" name="address" type="text" value="@Model.Registration.Address" placeholder="Address">

                </div>

                  <div class="form-group mb-3">

                    <label class="form-label" for="Person">Ref Person</label>

                      <input class="form-control" id="refperson" name="refperson" type="text" value="@Model.Registration.RefPerson" placeholder="Ref Person">

                </div>

                  <div class="form-group mb-3">

                    <label class="form-label" for="RMobile">Ref Mobile No</label>

                    <input class="form-control" id="refmobile" name="refmobile" type="text" value="@Model.Registration.RefMobile" placeholder="Ref Mobile">

                </div>

                <div class="form-group mb-3">

                    <label class="form-label" for="bio">Bio</label>

                    <textarea class="form-control" id="bio" name="bio" cols="30" rows="10" placeholder="Working as UX/UI Designer at Designing World since 2016.">@Model.Registration.Bio</textarea>

                </div>

                <div class="kt-portlet__foot">

                    <div class="kt-form__actions">

                        <div class="row">

                            <div class="col-lg-9 ml-lg-auto">

                                <button type="submit" class="btn btn-success">Submit</button>

                                <a href="/Admin/Visitor" class="btn btn-outline-danger">Cancel</a>


                            </div>

                        </div>

                    </div>

                </div>



            }

        </div>



            public ActionResult Visitor()

            {

                if (Request.Cookies["mysocietyCookies"] != null)

                {

                    MainModel itemnew = new MainModel();


                    itemnew.RegistrationList = RegistrationManager.GetAll();


                    string sid = Request.Cookies["mysocietyCookies"].Value;

                    string[] AllArray = sid.Split(',');

                    ViewBag.UserName = AllArray[1];

                    ViewBag.SMS = AllArray[2];

                    ViewBag.Pic = AllArray[3];


                    ViewBag.Msg = "";

                    ViewBag.Msg = (TempData[Constant.INFO_MESSAGE] != null ? TempData[Constant.INFO_MESSAGE] : string.Empty).ToString();

                    TempData[Constant.INFO_MESSAGE] = "";

                    ViewBag.TypeCss = "success";

                    ViewBag.MsgTitle = "Success!";


                    Guid RefId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out RefId);


                    itemnew.PermissionList = PermissionManager.GetByUserId(RefId);


                    return View("~/Views/Admin/Visitor.cshtml", new MainModel { PermissionList = itemnew.PermissionList, RegistrationList = itemnew.RegistrationList });

                }

                else

                    return View("~/Views/Account/Login.cshtml");

            }

            public ActionResult AddVisitor(Guid Id)

            {

                if (Request.Cookies["mysocietyCookies"] != null)

                {

                    MainModel itemnew = new MainModel();

                    string sid = Request.Cookies["mysocietyCookies"].Value;

                    string[] AllArray = sid.Split(',');

                    ViewBag.UserName = AllArray[1];

                    ViewBag.SMS = AllArray[2];

                    ViewBag.Pic = AllArray[3];


                    List<Society> societyList = SocietyManager.GetAll().ToList();

                    List<Tower> towerList = TowerManager.GetAll().ToList();

                    List<Flower> floorList = FlowerManager.GetAll().ToList();

                    if (Id != Guid.Empty)

                    {

                        itemnew.Registration = RegistrationManager.GetById(Id);

                        ViewBag.job = new SelectList(Constant.VisitorJob, "Text", "Value", itemnew.Registration.Category);

                    }

                    else

                    {

                        ViewBag.job = new SelectList(Constant.VisitorJob, "Text", "Value");

                    }




                    Guid RefId = Guid.Empty;

                    Guid.TryParse(AllArray[0], out RefId);


                    itemnew.PermissionList = PermissionManager.GetByUserId(RefId);


                    return View("~/Views/AllForms/AddVisitor.cshtml", new MainModel { PermissionList = itemnew.PermissionList, Registration = itemnew.Registration });

                }

                else

                    return View("~/Views/Account/Login.cshtml");

            }

            public ActionResult SaveVisitor(FormCollection coll, HttpPostedFileBase fileupload)

            {

                MainModel itemnew = new MainModel();


                Guid Id = Guid.Empty;

                Guid.TryParse(coll["Id"], out Id);


                Registration obj = new Registration();


                if (Id != Guid.Empty)

                {

                    Registration oldobj = RegistrationManager.GetById(Id);

                    if (oldobj != null)

                        obj = oldobj;

                }


                obj.EmailId = coll["email"];

                obj.MobileNo = coll["mobileno"];

                obj.Password = coll["registerPassword"];

                obj.Role = Guid.Empty;

                obj.Name = coll["name"];

                obj.Status = "Active";

                obj.Extra1 = "00000000-0000-0000-0000-000000000000";

                obj.Extra2 = "Visitor";

                obj.Category = coll["drpjob"];

                obj.Address = coll["address"];


                obj.DocUpload1 = "";

                obj.DocUpload2 = "";

                obj.Tower = "00000000-0000-0000-0000-000000000000";

                obj.FlatNo = "00000000-0000-0000-0000-000000000000";

                obj.SocietyId = Guid.Empty;

                obj.RegCode = auto();

                obj.App_Date = DateTime.Now.ToString("dd-MM-yyyy");

                obj.InTime = DateTime.Now;

                obj.OutTime = DateTime.Now;


                obj.RefPerson = coll["refperson"];

                obj.RefMobile = coll["refmobile"];

              

                obj.Extra3 = "";

                obj.Extra4 = "";

                obj.Bio = coll["bio"];


                if (Id != Guid.Empty)

                {

                    if (fileupload != null)

                    {

                        if (fileupload.ContentLength > 0)

                        {

                            string _FileName = Path.GetFileName(fileupload.FileName);

                            string _path = Path.Combine(Server.MapPath("../UserImage/"), _FileName);

                            fileupload.SaveAs(_path);


                            obj.Pic = "../UserImage/" + _FileName;

                        }

                        else

                            obj.Pic = obj.Pic;

                    }

                    else

                        obj.Pic = obj.Pic;


                    obj.CreatedBy = "00000000-0000-0000-0000-000000000000";

                    obj.UpdatedBy = "Admin";

                    obj.UpdatedOn = DateTime.Now;

                    RegistrationManager.Update(obj);


                    TempData[Constant.INFO_MESSAGE] = "Record Updated Successfully";

                }

                else

                {

                    if (fileupload != null)

                    {

                        if (fileupload.ContentLength > 0)

                        {

                            string _FileName = Path.GetFileName(fileupload.FileName);

                            string _path = Path.Combine(Server.MapPath("../UserImage/"), _FileName);

                            fileupload.SaveAs(_path);


                            obj.Pic = "../UserImage/" + _FileName;

                        }

                        else

                            obj.Pic = "../UserImage/noimage.png";

                    }

                    else

                        obj.Pic = "../UserImage/noimage.png";


                    obj.Id = Guid.NewGuid();

                    obj.CreatedBy = "00000000-0000-0000-0000-000000000000";

                    obj.UpdatedBy = "Admin";

                    obj.CreatedOn = obj.UpdatedOn = DateTime.Now;


                    RegistrationManager.Add(obj);


                    TempData[Constant.INFO_MESSAGE] = "Record Added Successfully.";

                }


                return RedirectToAction("Visitor");

            }

            public ActionResult DeleteVisitor(Guid Id)

            {

                MainModel itemnew = new MainModel();


                if (Id != Guid.Empty)

                {

                    Registration obj = RegistrationManager.GetById(Id);

                    if (obj != null)

                        RegistrationManager.Delete(obj);


                    TempData[Constant.INFO_MESSAGE] = "Record Deleted Successfully.";

                }

                else

                {

                    TempData[Constant.INFO_MESSAGE] = "Record Not Deleted.";

                }


                return RedirectToAction("Visitor");

            }

            public ActionResult ApproveVisitor(Guid Id)

            {

                Registration obj = RegistrationManager.GetById(Id);

                if (obj != null)

                {

                    SqlCommand cmd = new SqlCommand("Update Registration set Status=@Status where Id=@Id", con);


                    if (obj.Status == "Active")

                        cmd.Parameters.AddWithValue("@Status", "Pending");

                    else

                        cmd.Parameters.AddWithValue("@Status", "Active");


                    cmd.Parameters.AddWithValue("@Id", Id);

                    con.Open();

                    cmd.ExecuteNonQuery();

                    con.Close();

                }


                return RedirectToAction("Visitor");

            }

  • You might also like

    No comments :

    Post a Comment