Esempio n. 1
0
        public ActionResult InserRequisition(ICollection<RequisitionViewModel> requisitionDetail, FormCollection form,
                                             string datepicker, string rNumber)
        {
            if (rNumber.Trim() == string.Empty)
                return RedirectToAction("ApprovedRequisitions", "HubAllocation");

            var userName = HttpContext.User.Identity.Name;
            var user = _userAccountService.GetUserDetail(userName);

            if (ModelState.IsValid && requisitionDetail !=null )
            {
                string hub = form["hub"].ToString(CultureInfo.InvariantCulture); //retrives Hub id from the view
                DateTime date;

                try
                {
                    date = DateTime.Parse(datepicker);
                        //checkes if date is ethiopian date. if it is then it will enter to the catch and convert to gragorian to persist.
                }
                catch (Exception exception)
                {
                    var log = new Logger();
                    log.LogAllErrorsMesseges(exception,_log);
                    var strEth = new getGregorianDate();
                    date = strEth.ReturnGregorianDate(datepicker);
                }

                foreach (RequisitionViewModel appRequisition in requisitionDetail)
                {

                    var newHubAllocation = new HubAllocation
                                               {
                                                   AllocatedBy = user.UserProfileID,
                                                   RequisitionID = appRequisition.RequisitionId,
                                                   AllocationDate = date,
                                                   ReferenceNo = rNumber,
                                                   HubID = int.Parse(hub)
                                               };

                    _hubAllocationService.AddHubAllocation(newHubAllocation);

                }
                return RedirectToAction("ApprovedRequisitions", "HubAllocation");

            }
            return RedirectToAction("ApprovedRequisitions", "HubAllocation");
        }
 private DateTime GetGregorianDate(string ethiopianDate)
 {
     DateTime convertedGregorianDate;
     try
     {
         convertedGregorianDate = DateTime.Parse(ethiopianDate);
     }
     catch (Exception ex)
     {
         var strEth = new getGregorianDate();
         convertedGregorianDate = strEth.ReturnGregorianDate(ethiopianDate);
     }
     return convertedGregorianDate;
 }
        public ActionResult SaveProjectAllocation(RequisitionViewModel requisitionViewModel, 
                                                    FormCollection form, 
                                                    string hub, 
                                                    string datepicker,
                                                    int RequisitionId,
                                                    int Remaining=0, 
                                                    int PCodeqty=0, 
                                                    int SICodeqty=0)
        {
            DateTime date;
            bool isProjectCodeSelected = false;
            bool isSICodeSelected = false;

            try
            {
                date = DateTime.Parse(datepicker);
                //checkes if date is ethiopian date. if it is then it will enter to the catch and convert to gragorian for  persistance.
            }
            catch (Exception)
            {

                var strEth = new getGregorianDate();
                date = strEth.ReturnGregorianDate(datepicker);
            }

            bool isLastAssignment = false;
            int? pCode =null;
            int? siCode=null;

            if (Remaining < PCodeqty + SICodeqty)
            {
                ModelState.AddModelError("Errors",@"Amount entered is greater than the remaining quantity ");
                TempData["ModelState"] = ModelState;
                return RedirectToAction("Assign", "ProjectAllocation", new { ReqId= RequisitionId, Remaining = Remaining});

            }

            var requisitionId = requisitionViewModel.RequisitionId;

            try
            {
                pCode = int.Parse(form["PCCode"].ToString(CultureInfo.InvariantCulture));
                isProjectCodeSelected = true;
            }
            catch
            {
                pCode = null;
            }

            try
            {
                siCode = int.Parse(form["SICode"].ToString(CultureInfo.InvariantCulture));
                isSICodeSelected = true;
            }
            catch(Exception ex)
            {
                 siCode = null;
                var log = new Logger();
                log.LogAllErrorsMesseges(ex,_log);

            }

            if (isProjectCodeSelected == false && isSICodeSelected == false)
            {
                ModelState.AddModelError("Errors", @"SI code or Project Code is not selected.");
                TempData["ModelState"] = ModelState;
                return RedirectToAction("Assign", "ProjectAllocation", new { ReqId = RequisitionId, Remaining = Remaining });
            }

            if ((isProjectCodeSelected && PCodeqty == 0) || (isSICodeSelected && SICodeqty == 0))
            {
                ModelState.AddModelError("Errors", @"Value entered for Projecte Code/SI Code is zero or Invalid. ");
                TempData["ModelState"] = ModelState;
                return RedirectToAction("Assign", "ProjectAllocation", new { ReqId = RequisitionId, Remaining = Remaining });
            }

            var hubAllocation = _hubAllocationService.GetAllocatedHubByRequisitionNo(requisitionId);
            var newProjectAllocation = new ProjectCodeAllocation
                                           {

                                               AllocatedBy = 1,
                                               AlloccationDate = date,
                                               Amount_FromProject = PCodeqty,
                                               ProjectCodeID = pCode,
                                               Amount_FromSI = SICodeqty,
                                               SINumberID = siCode,
                                               HubAllocationID = hubAllocation.HubAllocationID
                                           };

            if (Remaining == PCodeqty + SICodeqty)
                isLastAssignment = true;
            try
            {
                _projectCodeAllocationService.AddProjectCodeAllocation(newProjectAllocation, requisitionId, isLastAssignment);

            }
            catch(Exception exception)
            {

                var log = new Logger();
                log.LogAllErrorsMesseges(exception,_log);
                ModelState.AddModelError("Errors",@"Can't add new project code allocation");

            }

               if (isLastAssignment)
               {
               return RedirectToAction("AllocateProjectCode", "ProjectAllocation");
               }
               else
               {
               return RedirectToAction("AssignedprojectCodes", "ProjectAllocation",new {requisitionId= requisitionId});
               }
        }