示例#1
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id != null)
            {
                Worker worker = await db.Workers.FirstOrDefaultAsync(t => t.WorkerID == id);

                if (worker == null)
                {
                    ErrorViewModel error = new ErrorViewModel
                    {
                        RequestId = "Error! There is no record in the database with the id passed = " + id
                    };
                    return(View("Error", error));
                }
                EditWorkerViewModel model = new EditWorkerViewModel
                {
                    Id         = worker.WorkerID,
                    WorkerFIO  = worker.WorkerFIO,
                    WorkerPost = worker.WorkerPost
                };
                return(View(model));
            }
            else
            {
                ErrorViewModel error = new ErrorViewModel {
                    RequestId = "Error! Missing id in request parameters"
                };
                return(View("Error", error));
            }
        }
示例#2
0
        public async Task <IActionResult> Edit(EditWorkerViewModel model)
        {
            int    er     = 0;
            Worker worker = await db.Workers.FirstOrDefaultAsync(t => t.WorkerID == model.Id);

            if (ModelState.IsValid && (model.WorkerFIO == worker.WorkerFIO || (er = db.Workers.Count(p => p.WorkerFIO == model.WorkerFIO)) == 0))
            {
                if (worker == null)
                {
                    ErrorViewModel error = new ErrorViewModel
                    {
                        RequestId = "Error! Empty model was sent"
                    };
                    return(View("Error", error));
                }
                worker.WorkerFIO  = model.WorkerFIO;
                worker.WorkerPost = model.WorkerPost;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            if (er != 0)
            {
                ModelState.AddModelError("WorkerFIO", "Record with the same FIO already exists");
            }
            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id)
        {
            var workers = await _dbContext.Workers.FindAsync(id);

            EditWorkerViewModel workerViewModel = new EditWorkerViewModel()
            {
                Id                     = workers.Id,
                Name                   = workers.Name,
                Surname                = workers.Surname,
                FatherName             = workers.FatherName,
                BirthdayDate           = workers.BirthdayDate,
                CurrentAdress          = workers.CurrentAdress,
                DistrictRegistration   = workers.DistrictRegistration,
                PassportNumber         = workers.PassportNumber,
                PassportExpirationDate = workers.PassportExpirationDate,
                EducationType          = workers.EducationType,
                MartialStatus          = workers.MartialStatus,
                Gender                 = workers.Gender,
                EmailAddress           = workers.EmailAddress,
                ExistingPath           = workers.PhotoPath
            };

            //Yoxladim
            if (workers == null)
            {
                return(Redirect("/Home/Error"));
            }

            return(View(workerViewModel));
        }
示例#4
0
        public async Task <IActionResult> EditWorker(EditWorkerViewModel model)
        {
            Worker worker = await db.Workers.FirstOrDefaultAsync(t => t.workerID == model.Id);

            int er = 0;

            if (ModelState.IsValid && (model.fioWorker == worker.fioWorker || (er = db.Workers.Count(p => p.fioWorker == model.fioWorker)) == 0))
            {
                if (worker == null)
                {
                    ErrorViewModel error = new ErrorViewModel
                    {
                        RequestId = "Ошибка! Прислана пустая модель"
                    };
                    return(View("Error", error));
                }
                worker.fioWorker        = model.fioWorker;
                worker.dateOfEmployment = model.dateOfEmployment;
                worker.dateOfDismissal  = model.dateOfDismissal;
                worker.salary           = model.salary;
                await db.SaveChangesAsync();

                return(RedirectToAction("Workers", new { id = worker.postID }));
            }
            if (er != 0)
            {
                ModelState.AddModelError("fioWorker", "Запись с таким именем уже есть");
            }
            return(View(model));
        }
示例#5
0
        public async Task <IActionResult> Delete(EditWorkerViewModel model)
        {
            var workers = await _dbContext.Workers.FindAsync(model.Id);

            workers.Name                   = model.Name;
            workers.Surname                = model.Surname;
            workers.FatherName             = model.FatherName;
            workers.BirthdayDate           = model.BirthdayDate;
            workers.CurrentAdress          = model.CurrentAdress;
            workers.DistrictRegistration   = model.DistrictRegistration;
            workers.PassportNumber         = model.PassportNumber;
            workers.PassportExpirationDate = model.PassportExpirationDate;
            workers.EducationType          = model.EducationType;
            workers.MartialStatus          = model.MartialStatus;
            workers.Gender                 = model.Gender;
            workers.EmailAddress           = model.EmailAddress;
            if (workers.PhotoPath != null)
            {
                string filePath = Path.Combine(hostingEnvironment.WebRootPath, "workerImages", workers.PhotoPath);
                System.IO.File.Delete(filePath);
            }

            _dbContext.Workers.Remove(workers);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(List)));
        }
示例#6
0
        public async Task <IActionResult> Details(int id)
        {
            var data = await _dbContext.Workers.FindAsync(id);

            if (data == null)
            {
                return(Redirect("/Home/Error"));
            }

            EditWorkerViewModel worker = new EditWorkerViewModel()
            {
                Id                     = data.Id,
                Name                   = data.Name,
                Surname                = data.Surname,
                FatherName             = data.FatherName,
                BirthdayDate           = data.BirthdayDate,
                CurrentAdress          = data.CurrentAdress,
                DistrictRegistration   = data.DistrictRegistration,
                PassportNumber         = data.PassportNumber.ToUpper(),
                PassportExpirationDate = data.PassportExpirationDate,
                EducationType          = data.EducationType,
                MartialStatus          = data.MartialStatus,
                Gender                 = data.Gender,
                EmailAddress           = data.EmailAddress,
                ExistingPath           = data.PhotoPath
            };

            return(View(worker));
        }
示例#7
0
        public IActionResult EditWorker(int workerId)
        {
            var user = _userService.GetById(workerId);

            if (!user.Success)
            {
                return(RedirectToAction("InternalError", "Error", new { errorMessage = user.Message }));
            }

            var manager = _workerService.GetById(workerId);

            if (!manager.Success)
            {
                return(RedirectToAction("InternalError", "Error", new { errorMessage = manager.Message }));
            }

            var editWorkerDto = new EditWorkerDto
            {
                AddressNumber = manager.Data.AddressNumber,
                LastName      = user.Data.LastName,
                IdentityNo    = manager.Data.IdentityNo,
                GenderId      = user.Data.GenderId,
                Street        = manager.Data.Street,
                FirstName     = user.Data.FirstName,
                CityId        = manager.Data.CityId,
                Email         = user.Data.Email,
                DistrictId    = manager.Data.DistrictId,
                PhoneNumber   = user.Data.PhoneNumber,
                WorkerId      = workerId
            };

            var model = new EditWorkerViewModel
            {
                EditWorkerDto          = editWorkerDto,
                GenderNamesSelectItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Cinsiyet", Value = "0"
                    }
                }
            };

            foreach (var gender in _genderDal.GetList())
            {
                bool selected = gender.GenderId == user.Data.GenderId;
                model.GenderNamesSelectItems.Add(new SelectListItem
                {
                    Text     = gender.GenderName,
                    Value    = gender.GenderId.ToString(),
                    Selected = selected
                });
            }

            return(View(model));
        }
示例#8
0
        public async Task <IActionResult> Edit(EditWorkerViewModel model)
        {
            if (model.PassportExpirationDate <= DateTime.Now)
            {
                ModelState.AddModelError("PassportExpirationDate", "Passportunuzun son istifade tarixi bitmişdir");
            }

            else
            {
                if (ModelState.IsValid)
                {
                    var workers = await _dbContext.Workers.FindAsync(model.Id);

                    workers.Name                   = model.Name;
                    workers.Surname                = model.Surname;
                    workers.FatherName             = model.FatherName;
                    workers.BirthdayDate           = model.BirthdayDate;
                    workers.CurrentAdress          = model.CurrentAdress;
                    workers.DistrictRegistration   = model.DistrictRegistration;
                    workers.PassportNumber         = model.PassportNumber;
                    workers.PassportExpirationDate = model.PassportExpirationDate;
                    workers.EducationType          = model.EducationType;
                    workers.MartialStatus          = model.MartialStatus;
                    workers.EmailAddress           = model.EmailAddress;
                    workers.Gender                 = model.Gender;
                    if (model.Photo != null)
                    {
                        if (model.ExistingPath != null)
                        {
                            string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                           "workerImages", model.ExistingPath);
                            System.IO.File.Delete(filePath);
                        }
                        workers.PhotoPath = ProcessUploadFile(model);
                    }

                    _dbContext.Workers.Update(workers);
                    await _dbContext.SaveChangesAsync();

                    return(RedirectToAction(nameof(List)));
                }
            }
            return(View());
        }
        public async Task <ActionResult> Edit(EditWorkerViewModel model, string act)
        {
            if (ModelState.IsValid)
            {
                Worker worker = await db.Workers.FindAsync(model.Id);

                if (model.Avatar != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(model.Avatar.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)model.Avatar.Length);
                    }

                    worker.Avatar = imageData;
                }

                worker.FullName       = model.FullName;
                worker.Email          = model.Email;
                worker.EmailConfirmed = model.EmailConfirmed;
                worker.Position       = model.Position;
                worker.Status         = model.Status;
                worker.Education      = model.Education;


                await db.SaveChangesAsync();

                if (act == "Confirm")
                {
                    return(RedirectToAction(act, new { id = worker.Id }));
                }
                return(RedirectToAction(act));
            }
            return(View(model));
        }
        public async Task <ActionResult> Edit(int?id)
        {
            if (id != null)
            {
                Worker worker = await db.Workers.FindAsync(id);

                if (worker != null)
                {
                    EditWorkerViewModel workerView = new EditWorkerViewModel()
                    {
                        Id             = worker.Id,
                        FullName       = worker.FullName,
                        Education      = worker.Education,
                        Email          = worker.Email,
                        EmailConfirmed = worker.EmailConfirmed,
                        Position       = worker.Position,
                        Status         = worker.Status,
                        Picture        = worker.Avatar
                    };
                    return(View(workerView));
                }
            }
            return(NotFound());
        }
示例#11
0
        public async Task <IActionResult> EditWorker(int?id)
        {
            if (id != null)
            {
                Worker worker = await db.Workers.Include("Post").FirstOrDefaultAsync(t => t.workerID == id);

                if (worker != null)
                {
                    EditWorkerViewModel model = new EditWorkerViewModel
                    {
                        Id               = worker.workerID,
                        fioWorker        = worker.fioWorker,
                        postName         = worker.Post.postName,
                        dateOfEmployment = worker.dateOfEmployment,
                        dateOfDismissal  = worker.dateOfDismissal,
                        salary           = worker.salary
                    };
                    return(View(model));
                }
                else
                {
                    ErrorViewModel error = new ErrorViewModel
                    {
                        RequestId = "Ошибка! В базе данных отсутствует запись с переданным  id = " + id
                    };
                    return(View("Error", error));
                }
            }
            else
            {
                ErrorViewModel error = new ErrorViewModel {
                    RequestId = "Ошибка! Отсутствует id в параметрах запроса"
                };
                return(View("Error", error));
            }
        }
示例#12
0
        // GET: Players/Edit/5
        public ActionResult Manage(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // Retrieve Worker from db and perform null check
            //Worker worker = db.Workers.Find(id);
            var result = from s in db.SYSUsers
                         join p in db.SYSUserProfiles on s.SYSUserID equals p.SYSUserID
                         join t in db.UserTypes on p.UserTypeID equals t.ID
                         where t.ID.Equals((int)UserType.w)
                         select new Worker
            {
                ID        = s.SYSUserID,                                 //Guid.Parse("1"),    //s.SYSUserID.ToString()
                FirstName = p.FirstName,
                LastName  = p.LastName,
                Mobile    = p.Mobile,
                Email     = p.Email
            };

            List <Worker> wlist  = result.ToList();
            Worker        worker = wlist[0];

            if (worker == null)
            {
                return(HttpNotFound());
            }
            worker.WorkerId = (Guid)id;
            // Instantiate new instance of EditWorkerViewModel
            EditWorkerViewModel model = new EditWorkerViewModel
            {
                // Can set the Worker name and Id filds of the ViewModel
                WorkerId = worker.WorkerId.ToString(),
                Name     = worker.FirstName
            };



            // Retrieve list of worker jobs from db in order to find the teams that the Worker belongs to
            //  var workerJobs = db.Jobs.Where(i => i.Workers.Any(j => j.WorkerId.Equals(worker.WorkerId))).ToList();
            var qworkerJobs = from s in db.SYSUsers
                              join p in db.SYSUserProfiles on s.SYSUserID equals p.SYSUserID
                              join t in db.UserTypes on p.UserTypeID equals t.ID
                              join j in db.JOBs on s.SYSUserID equals j.WorkerID
                              //where j.WorkerID.Equals(1)
                              select new Job
            {
                JobId = Guid.NewGuid()
            };
            var        jlist      = qworkerJobs.ToList();
            List <Job> workerJobs = jlist;

            //var WorkerJobs = db.Jobs.Where(t => t.Workers.Contains(new Worker { WorkerId = worker.WorkerId })).ToList();

            // Check that workerJobs is not empty
            if (workerJobs != null)
            {
                // Initialize the array to number of teams in workerTeams
                string[] workerJobsIds = new string[workerJobs.Count()];

                // Then, set the value of platerTeams.Count so the for loop doesn't need to work it out every iteration
                int length = workerJobs.Count();

                // Now loop over each of the workerJobs and store the Id in the workerJobsId array
                for (int i = 0; i < length; i++)
                {
                    // Note that we employ the ToString() method to convert the Guid to the string
                    // workerJobs[i].JobId = new Guid(string.Format("00000000-0000-0000-0000-00{0:0000000000}", workerJobs[i].ID));       //Guid.Parse(workerJobs[i].ID.ToString());

                    workerJobsIds[i] = workerJobs[i].JobId.ToString();
                }

                // Instantiate the MultiSelectList, plugging in our playerTeamIds array
                MultiSelectList jobsList = new MultiSelectList(db.JOBs.ToList().OrderBy(i => i.Description), "ID", "Description", workerJobsIds);

                // Now add the teamsList to the Teams property of our EditPlayerViewModel (model)
                model.Jobs   = jobsList;
                model.JobIds = workerJobsIds.ToList();
                // Return the ViewModel
                return(View(model));
            }
            else
            {
                // Else instantiate the teamsList without any pre-selected values
                MultiSelectList jobsList = new MultiSelectList(db.JOBs.ToList().OrderBy(i => i.Description), "JobId", "Name");

                // Set the Teams property of the EditWorkerViewModel with the teamsList
                model.Jobs = jobsList;

                // Return the ViewModel
                return(View(model));
            }
        }