示例#1
0
        public ActionResult CreateNewPassword(Registration userr)
        {
            try
            {
                if (userr.UserId > 0)
                {
                    Registration reg = _context.Registration.FirstOrDefault(m => m.UserId == userr.UserId);
                    reg.Password        = userr.Password;
                    reg.ConfirmPassword = userr.ConfirmPassword;

                    _context.Update(reg);
                    _context.SaveChangesAsync();
                    HttpContext.Session.SetString(SessionEmpName, reg.Email);
                    HttpContext.Session.SetString(SessionISRole, reg.Role);
                    HttpContext.Session.SetString(SessionIsLogin, "1");
                    return(RedirectToAction("Index", "Department"));
                }
            }
            catch (Exception ex)
            {
                string message = string.Format("<b>Message:</b> {0}<br /><br />", ex.Message);
                message += string.Format("<b>StackTrace:</b> {0}<br /><br />", ex.StackTrace.Replace(Environment.NewLine, string.Empty));
                message += string.Format("<b>Source:</b> {0}<br /><br />", ex.Source.Replace(Environment.NewLine, string.Empty));
                message += string.Format("<b>TargetSite:</b> {0}", ex.TargetSite.ToString().Replace(Environment.NewLine, string.Empty));
                ModelState.AddModelError(string.Empty, message);
            }
            return(View(userr));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Department_Id,Department_Name")] DepartmentMaster departmentMaster)
        {
            if (id != departmentMaster.Department_Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (_context.DepartmentMaster.Any(name => name.Department_Name.Equals(departmentMaster.Department_Name) && name.Department_Id != departmentMaster.Department_Id && name.IsDelete == 0))
                    {
                        ModelState.AddModelError(string.Empty, "Department is already exists");
                        return(View(departmentMaster));
                    }
                    else
                    {
                        departmentMaster.IsDelete = 0;
                        _context.Update(departmentMaster);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentMasterExists(departmentMaster.Department_Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(departmentMaster));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Employee_Id,Employee_Name,Department_Id,JoiningDate,Address,IsDelete,Email,MobileNo,Image")] EmployeeMaster employeeMaster)
        {
            if (id != employeeMaster.Employee_Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (_context.EmployeeMaster.Any(name => name.Email.Equals(employeeMaster.Email) && name.Employee_Id != employeeMaster.Employee_Id && name.IsDelete == 0))
                    {
                        ModelState.AddModelError(string.Empty, "Employee is already exists");
                        var DepartmentLists = _context.DepartmentMaster.Where(s => s.IsDelete == 0).ToList();
                        ViewBag.Department = new SelectList(DepartmentLists, "Department_Id", "Department_Name");
                        return(View(employeeMaster));
                    }
                    else
                    {
                        var files = HttpContext.Request.Form.Files;
                        foreach (var Image in files)
                        {
                            if (Image != null && Image.Length > 0)
                            {
                                var supportedTypes = new[] { "jpg", "jpeg", "png", "gif", "bmp" };
                                var fileExt        = System.IO.Path.GetExtension(Image.FileName).Substring(1);
                                if (!supportedTypes.Contains(fileExt))
                                {
                                    string ErrorMessage = "File Extension Is InValid - Only Upload Image File";
                                    ModelState.AddModelError(string.Empty, ErrorMessage);
                                    var DepartmentLists = _context.DepartmentMaster.Where(s => s.IsDelete == 0).ToList();
                                    ViewBag.Department = new SelectList(DepartmentLists, "Department_Id", "Department_Name");
                                    return(View(employeeMaster));
                                }

                                var file    = Image;
                                var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "Emp_IMg");

                                if (file.Length > 0)
                                {
                                    var fileName = ContentDispositionHeaderValue.Parse
                                                       (file.ContentDisposition).FileName.ToString().Trim('"');

                                    System.Console.WriteLine(fileName);
                                    using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
                                    {
                                        await file.CopyToAsync(fileStream);

                                        employeeMaster.Image = file.FileName;
                                    }
                                }
                            }
                        }
                        //  employeeMaster.Department_Id = 2;
                        employeeMaster.IsDelete = 0;
                        _context.Update(employeeMaster);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeMasterExists(employeeMaster.Employee_Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeMaster));
        }