public ActionResult SignUp()
        {
            AgencyIndividualModel agencyIndividualModel = new Models.AgencyIndividualModel();
            List <CategoryModel>  CategoryList          = new List <CategoryModel>();

            var categories = _CategoryService.GetCategories();

            Mapper.CreateMap <HomeHelp.Entity.Category, HomeHelp.Models.CategoryModel>();
            foreach (var category in categories)
            {
                CategoryModel categoryModel = Mapper.Map <HomeHelp.Entity.Category, HomeHelp.Models.CategoryModel>(category);
                CategoryList.Add(categoryModel);
            }
            agencyIndividualModel.CategoryData = CategoryList;
            //UserPermissionAction("vendor", RoleAction.view.ToString(), operation, ShowMessage, MessageBody);
            return(View(agencyIndividualModel));
        }
        public ActionResult UpdateProfile([Bind(Include = "AgencyIndividualId,EmailId,FullName,WorkRate,ContactNumber,Address,Latitude,Longitude")]
                                          AgencyIndividualModel model, HttpPostedFileBase file)
        {
            AgencyIndividualModel agencyIndividualModel = new Models.AgencyIndividualModel();
            List <CategoryModel>  CategoryList          = new List <CategoryModel>();
            var categories = _CategoryService.GetCategories();

            //UserPermissionAction("vendor", RoleAction.view.ToString(), operation, ShowMessage, MessageBody);
            if (string.IsNullOrEmpty(model.FullName))
            {
                ModelState.AddModelError("FullName", "");
                return(View(model));
            }
            if (model.WorkRate == null)
            {
                ModelState.AddModelError("WorkRate", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.ContactNumber))
            {
                ModelState.AddModelError("ContactNumber", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.Address))
            {
                ModelState.AddModelError("Address", "");
                return(View(model));
            }

            try
            {
                if (ModelState.IsValid)
                {
                    string name = "";
                    if (file != null && file.ContentLength > 0)
                    {
                        try
                        {
                            if (file != null && file.ContentLength > 0)
                            {
                                name = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                                string path = Path.Combine(Server.MapPath("~/AgencyImage"), name);
                                file.SaveAs(path);
                            }
                        }
                        catch (Exception ex)
                        {
                            ViewBag.Message = "ERROR:" + ex.Message.ToString();
                        }
                    }
                    var existingUser = _UserService.GetUserByEmailId(model.EmailId);
                    if (existingUser != null)
                    {
                        existingUser.FirstName     = model.FullName;
                        existingUser.LastUpdatedOn = DateTime.Now;
                        _UserService.UpdateUser(existingUser);

                        var agencyIndividualDetail = _AgencyIndividualService.GetAgencyIndividualById(model.AgencyIndividualId);
                        if (agencyIndividualDetail != null)
                        {
                            agencyIndividualDetail.FullName      = model.FullName;
                            agencyIndividualDetail.Address       = model.Address;
                            agencyIndividualDetail.ContactNumber = model.ContactNumber;
                            agencyIndividualDetail.Latitude      = model.Latitude;
                            agencyIndividualDetail.Longitude     = model.Longitude;
                            agencyIndividualDetail.LastUpdatedOn = DateTime.Now;
                            agencyIndividualDetail.WorkRate      = model.WorkRate;
                            agencyIndividualDetail.PhotoPath     = name == ""?"":CommonCls.GetURL() + "/AgencyImage/" + name;
                            _AgencyIndividualService.UpdateAgencyIndividual(agencyIndividualDetail);
                            TempData["MessageBody"] = "Registeration done.";
                            ViewBag.Error           = TempData["MessageBody"];
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            TempData["MessageBody"] = "User not found.";
                            ViewBag.Error           = TempData["MessageBody"];
                            return(View(model));
                        }
                    }
                    else
                    {
                        TempData["MessageBody"] = "User not found.";
                        ViewBag.Error           = TempData["MessageBody"];
                        return(View(model));
                    }
                }
                else
                {
                    var errors           = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                    var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
                    TempData["MessageBody"] = "Please fill the required fields.";
                    ViewBag.Error           = TempData["MessageBody"];
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();//
                ErrorLogging.LogError(ex);
                return(View(model));
            }
        }
        public ActionResult SignUp([Bind(Include = "FullName,EmailId,Password,WorkRate,ContactNumber,Address,CategoryId,IsAgency,Latitude,Longitude")] AgencyIndividualModel model)
        {
            AgencyIndividualModel agencyIndividualModel = new Models.AgencyIndividualModel();
            List <CategoryModel>  CategoryList          = new List <CategoryModel>();
            var categories = _CategoryService.GetCategories();

            //UserPermissionAction("vendor", RoleAction.view.ToString(), operation, ShowMessage, MessageBody);
            if (string.IsNullOrEmpty(model.FullName))
            {
                ModelState.AddModelError("FullName", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.EmailId))
            {
                ModelState.AddModelError("EmailId", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError("Password", "");
                return(View(model));
            }
            if (model.WorkRate == null)
            {
                ModelState.AddModelError("WorkRate", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.ContactNumber))
            {
                ModelState.AddModelError("ContactNumber", "");
                return(View(model));
            }
            if (string.IsNullOrEmpty(model.Address))
            {
                ModelState.AddModelError("Address", "");
                return(View(model));
            }

            try
            {
                if (ModelState.IsValid)
                {
                    var existingUser = _UserService.GetUserByEmailId(model.EmailId);
                    if (existingUser == null)
                    {
                        UserModel userModel = new UserModel();
                        userModel.EmailId       = model.EmailId;
                        userModel.Password      = SecurityFunction.EncryptString(model.Password);
                        userModel.FirstName     = model.FullName;
                        userModel.CompanyId     = 2;
                        userModel.IsActive      = true;
                        userModel.CreatedOn     = DateTime.Now;
                        userModel.LastUpdatedOn = DateTime.Now;
                        Mapper.CreateMap <UserModel, User>();
                        var User = Mapper.Map <UserModel, User>(userModel);
                        _UserService.InsertUser(User);

                        var           getUserDetail = _UserService.GetUserByEmailId(model.EmailId);
                        UserRoleModel userRoleModel = new UserRoleModel();
                        userRoleModel.UserId = getUserDetail.UserId;
                        userRoleModel.RoleId = 4;
                        Mapper.CreateMap <UserRoleModel, UserRole>();
                        var UserRole = Mapper.Map <UserRoleModel, UserRole>(userRoleModel);
                        _UserRoleService.InsertUserRole(UserRole);

                        model.CreatedOn     = DateTime.Now;
                        model.LastUpdatedOn = DateTime.Now;
                        model.Password      = SecurityFunction.EncryptString(model.Password);
                        model.UserId        = getUserDetail.UserId;
                        model.IsAgency      = true;
                        model.IsActive      = true;
                        model.IsInvited     = true;
                        model.ParentId      = new Guid();
                        Mapper.CreateMap <AgencyIndividualModel, AgencyIndividual>();
                        var agencyIndividual = Mapper.Map <AgencyIndividualModel, AgencyIndividual>(model);
                        _AgencyIndividualService.InsertAgencyIndividual(agencyIndividual);
                        TempData["MessageBody"] = "Registeration done.";
                        ViewBag.Error           = TempData["MessageBody"];
                        return(RedirectToAction("LogOn"));
                    }
                    else
                    {
                        TempData["MessageBody"] = "Email already exists.";
                        ViewBag.Error           = TempData["MessageBody"];
                        return(View(model));
                    }
                }
                else
                {
                    TempData["MessageBody"] = "Please fill the required fields.";
                    ViewBag.Error           = TempData["MessageBody"];
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();//
                ErrorLogging.LogError(ex);
            }

            Mapper.CreateMap <HomeHelp.Entity.Category, HomeHelp.Models.CategoryModel>();
            foreach (var category in categories)
            {
                CategoryModel categoryModel = Mapper.Map <HomeHelp.Entity.Category, HomeHelp.Models.CategoryModel>(category);
                CategoryList.Add(categoryModel);
            }
            model.CategoryData      = CategoryList;
            TempData["MessageBody"] = "Something get wrong. please try again";
            ViewBag.Error           = TempData["MessageBody"];
            return(View(model));
        }