Exemple #1
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                //var record =await _leaveallocationrepo.FindById(model.Id);
                var record = await _unitOfWork.LeaveAllocations.Find(q => q.Id == model.Id);

                record.NumberOfDays = model.NumberOfDays;

                //var isSuccess =await _leaveallocationrepo.Update(record);

                //if (!isSuccess)
                //{
                //    ModelState.AddModelError("", "Something Went Wrong ...");
                //    return View(model);
                //}

                _unitOfWork.LeaveAllocations.Update(record);
                await _unitOfWork.Save();

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View());
            }
        }
Exemple #2
0
        public ActionResult Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                // TODO: Add update logic here
                var record = _leaverepo.FindById(model.Id);
                record.NumberOfDays = model.NumberOfDays;
                //var allocation = _mapper.Map<LeaveAllocation>(model);
                var isSuccess = _leaverepo.Update(record);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View());
            }
        }
Exemple #3
0
        public ActionResult Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = _leaveallocationrepo.FindById(model.Id);
                //var allocation = _mapper.Map<LeaveAllocation>(model);
                record.NumberOfDays = model.NumberOfDays;
                var UpdateSuccess = _leaveallocationrepo.Update(record);
                if (!UpdateSuccess)
                {
                    ModelState.AddModelError("", "Error while saving ...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _leaveAllocationRepo.FindById(model.Id);

                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = await _leaveAllocationRepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error while saving edit");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
Exemple #5
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                //Both Works

                //This one Updates Whole Model received here
                //var allocation = _mapper.Map<LeaveAllocation>(model);
                //var isSuccess = _leaveallocationrepo.Update(allocation);

                //This one model is created here and updated only one filed and then saved
                var record = await _leaveallocationrepo.FindById(model.Id);

                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = await _leaveallocationrepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error occured while saving data!");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
Exemple #6
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                int idd = model.Id;
                if (!ModelState.IsValid)
                {
                    var leaveallocation = await _repoleaveAllocation.FindById(idd);

                    var model1 = _mapper.Map <EditLeaveAllocationVM>(leaveallocation);
                    model1.NumberOfDays = model.NumberOfDays;
                    return(View(model1));
                }
                var record = await _repoleaveAllocation.FindById(model.Id);

                //var allocation = _mapper.Map<LeaveAllocation>(model);
                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = await _repoleaveAllocation.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error while saving ");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public ActionResult Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = _leaveAllocationRepo.FindById(model.Id);
                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = _leaveAllocationRepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "The Leave allocation was not edited...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Edit), new { id = model.Id }));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var recored = await _leaveallocationrepo.FindById(model.Id);

                recored.NumberOfDays = model.NumberOfDays;

                var isSuccess = await _leaveallocationrepo.update(recored);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error samooooooooooraaaa while saving");
                    return(View(model));
                }
                //just wanted to go back to my recored not show it from the scratch again! instead of index i choosed Details
                //details requiers id so i make a new parameter with the employee id as a value from the edit form
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public async Task <IActionResult> Edit(EditLeaveAllocationVM editLeaveAllocationVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var leaveAllocation = mapper.Map <LeaveAllocation>(editLeaveAllocationVM);
                    var isSuccess       = await leaveAllocationRepository.Update(leaveAllocation);

                    if (!isSuccess)
                    {
                        ModelState.AddModelError("", "Error while saving");
                    }
                    else
                    {
                        return(RedirectToAction(nameof(Details), new { employeeId = editLeaveAllocationVM.EmployeeId }));
                    }
                }

                return(View(editLeaveAllocationVM));
            }
            catch
            {
                return(View(editLeaveAllocationVM));
            }
        }
Exemple #10
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var record = await _LeaveAllocationrepo.FindById(model.id);

                record.NumberOfDays = model.NumberOfDays;

                var success = await _LeaveAllocationrepo.Update(record);

                if (!success)
                {
                    ModelState.AddModelError("", "error while saving");
                    return(View(model));
                }

                //redirect to Details. since Deatails takes a string id parameter,
                //we pass in a new object of model.EmployeeId as the parameter to be used in Details(string id)
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                // TODO: Add update logic here
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _leaveallocationrepo.FindById(model.Id);

                //var alocation = _mapper.Map<EditLeaveAllocationVM, LeaveAllocation>(model);
                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = await _leaveallocationrepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error while saving");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                //var allocation = _mapper.Map<LeaveAllocation>(model); does not work???
                var allocation = _leaveAllocationRepo.FindById(model.Id);
                allocation.NumberOfDays = model.NumberOfDays;
                var isSuccess = _leaveAllocationRepo.Update(allocation);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something has gone wrong!");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Something has gone wrong! " + ex.Message);
                return(View(model));
            }
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _leaveallocationrepo.FindById(model.Id);

                record.NumberOfDays = model.NumberOfDays;
                var isSuccess = await _leaveallocationrepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Error while saving");
                    return(View(model));
                }
                //no quiero retornar a Index, a la lista de leaveTypes. Quiero retronar a Details, y Details requiere un string id como prametro
                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public ActionResult Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = _Allocationrepo.FindByID(model.Id);
                record.NumberOfDays = model.NumberOfDays;

                var isSuccess = _Allocationrepo.Update(record);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong ...");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View(model));
            }
        }
Exemple #15
0
        public async Task <ActionResult> Edit(EditLeaveAllocationVM data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var record = await _leaveAllocationRepo.FindById(data.Id);

                    record.NumberOfDays = data.NumberOfDays;
                    var isSuccess = await _leaveAllocationRepo.Update(record);

                    if (!isSuccess)
                    {
                        ModelState.AddModelError("", "Something went wrong...");
                        return(View(data));
                    }
                    return(RedirectToAction(nameof(Details), new { id = data.EmployeeId }));
                }
                else
                {
                    return(View(data));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong...");
                return(View(data));
            }
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var allocation = await _leaveAllocationRepo.FindById(model.Id);

            allocation.NumberOfDays = model.NumberOfDays;
            var isSuccess = await _leaveAllocationRepo.Update(allocation);

            if (!isSuccess)
            {
                ModelState.AddModelError("", "Error al guardar");
                return(View(model));
            }
            await _leaveAllocationRepo.Save();

            return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
        }
        public async Task <ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var record = await _unitOfWork.LeaveAllocations.Find(expression : q => q.Id == model.Id);

                record.NumberOfDays = model.NumberOfDays;
                _unitOfWork.LeaveAllocations.Update(record);
                await _unitOfWork.Save();

                return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
            }
            catch
            {
                return(View());
            }
        }
Exemple #18
0
        public async Task<ActionResult> Edit(EditLeaveAllocationVM model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View(model);
                }
                var record = await _unitOfWork.LeaveAllocations.Find(q => q.Id == model.Id);
                record.NumberOfDays = model.NumberOfDays;
                _unitOfWork.LeaveAllocations.Update(record);
                await _unitOfWork.Save();

                // This is how you pass in a paramter to the action (new keyword)
                return RedirectToAction(nameof(Details), new { id = model.EmployeeId });
            }
            catch
            {
                ModelState.AddModelError("", "Error while saving");
                return View(model);
            }
        }
Exemple #19
0
 public ActionResult Edit(EditLeaveAllocationVM model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         var allocation = _mapper.Map <LeaveAllocation>(model);
         allocation.Period = DateTime.Now.Year;
         var isSuccess = _leaveallocationrepo.Update(allocation);
         if (!isSuccess)
         {
             ModelState.AddModelError("", "Error while saving");
             return(View(model));
         }
         return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(EditLeaveAllocationVM model)
 {
     try
     {
         // TODO: Add update logic here
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         var record = _leaveallocationrepo.FindById(model.Id);
         record.NumberOfDays = model.NumberOfDays;
         var isSuccess = _leaveallocationrepo.Update(record);
         if (!isSuccess)
         {
             ModelState.AddModelError("", "Error While Saving");
             return(View(model));
         }
         return(RedirectToAction(nameof(Details), new { id = model.EmployeeId }));
     }
     catch
     {
         return(View(model));
     }
 }