Beispiel #1
0
        public async Task <IActionResult> Edit(short id, [Bind("ActivityDetailWorkID,ActivityID,TotalSchool,ContractorID,ExpiryDate,Attachment")] ActivityDetailWork activityDetailWork)
        {
            if (id != activityDetailWork.ActivityDetailWorkID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(activityDetailWork);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActivityDetailWorkExists(activityDetailWork.ActivityDetailWorkID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActivityID"] = new SelectList(_context.Activity, "ActivityID", "Description", activityDetailWork.ActivityID);
            return(View(activityDetailWork));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(short id, [Bind("ActivityID,ProcurementPlanID,StepReferenceNo,Name,LotTotal,SchoolTotal,ProcurementFor,Description,EstimatedCost,ActualCost,MethodID,ReviewType,Status,IsCenceled,Remarks,CreatedDate,CreatedBy,UpdatedBy,UpdatedDate,ProjectNo")] Activity activity)
        {
            if (ModelState.IsValid)
            {
                var val = _context.Activity.Count(a => a.StepReferenceNo == activity.StepReferenceNo && a.ProcurementPlanID == id);
                if (val == 0)
                {
                    activity.ActualCost        = 0;
                    activity.CreatedDate       = DateTime.Now;
                    activity.Status            = 1;
                    activity.ProcurementPlanID = id;
                    if (id == 2)
                    {
                        activity.LotTotal = 1;
                    }
                    _context.Add(activity);
                    await _context.SaveChangesAsync();

                    if (activity.ProcurementPlanID == 2)// where 2 is Works
                    {
                        ActivityDetailWork Obj = new ActivityDetailWork();
                        Obj.ActivityID  = _context.Activity.Max(a => a.ActivityID);
                        Obj.TotalSchool = activity.SchoolTotal;
                        _context.Add(Obj);
                        await _context.SaveChangesAsync();
                    }
                    string  msg      = "Procurement: Added New Activity(" + _context.ProcurementPlan.Find(activity.ProcurementPlanID).Name + ")\nSTEP Reference# " + activity.StepReferenceNo + "\nName: " + activity.Name + "\nmore detail: http://eu.bep.org.pk";
                    ZongSMS ObjSMS   = new ZongSMS();
                    var     contacts = _context.Contact.Where(a => a.IsActive == true).ToList();
                    foreach (var contact in contacts)
                    {
                        ObjSMS.SendSingleSMS(msg, contact.ContactNumber);
                    }

                    return(RedirectToAction(nameof(Index), new { PPID = id }));
                }
                else
                {
                    ViewBag.Error = "Activity No." + activity.StepReferenceNo.ToString() + " already exist!";
                }
            }
            ViewBag.ReviewType = new SelectList(new[]
            {
                new { Id = "Prior Review", Name = "Prior Review" },
                new { Id = "Post Review", Name = "Post Review" },
            }, "Id", "Name");
            ViewBag.ProcurementFor = new SelectList(new[]
            {
                new { Id = "1", Name = "Schools" },
                new { Id = "2", Name = "Office" },
            }, "Id", "Name", activity.ProcurementFor);
            ViewBag.MethodID          = new SelectList(_context.Method, "MethodID", "Name", activity.MethodID);
            ViewBag.ProjectNo         = new SelectList(_context.Project, "ProjectNo", "ProjectName", 2);
            ViewBag.ProcurementPlanID = new SelectList(_context.ProcurementPlan.Where(a => a.ProcurementPlanID == id), "ProcurementPlanID", "Name", activity.ProcurementPlanID);
            return(View(activity));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ActivityDetailWorkID,ActivityID,TotalSchool,ContractorID,ExpiryDate,Attachment")] ActivityDetailWork activityDetailWork)
        {
            if (ModelState.IsValid)
            {
                _context.Add(activityDetailWork);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActivityID"] = new SelectList(_context.Activity, "ActivityID", "Description", activityDetailWork.ActivityID);
            return(View(activityDetailWork));
        }
        public async Task <IActionResult> Edit(string PPName, int ActualCost, [Bind("StepID,ActivityID,NotApplicable,PlannedDate,ActualDate,Attachment,CreatedBy,CreatedDate,UpdatedBy,UpdatedDate")] ActivityDetail activityDetail, IFormFile Attachment, DateTime ExpiryDate, short CID)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (activityDetail.NotApplicable == true)
                    {
                        activityDetail.Attachment  = null;
                        activityDetail.ActualDate  = null;
                        activityDetail.PlannedDate = null;
                    }
                    else
                    {
                        if (Attachment != null)
                        {
                            var rootPath = Path.Combine(
                                Directory.GetCurrentDirectory(), "wwwroot\\Documents\\Procurement\\");
                            string fileName = Path.GetFileName(Attachment.FileName);
                            fileName = fileName.Replace("&", "n");
                            string AName = _context.Activity.Find(activityDetail.ActivityID).Name;
                            AName = AName.Replace("&", "n");
                            //var PPName = _context.ProcurementPlan.Find(activityDetail.Step.ProcurementPlanID).Name;
                            activityDetail.Attachment = Path.Combine("/Documents/Procurement/", PPName + "/" + "//" + AName + "//" + activityDetail.StepID + "//" + fileName);//Server Path
                            //_context.ActivityDetail.Add(activityDetail);
                            string sPath = Path.Combine(rootPath + PPName + "/" + AName + "/", activityDetail.StepID.ToString());
                            if (!System.IO.Directory.Exists(sPath))
                            {
                                System.IO.Directory.CreateDirectory(sPath);
                            }
                            string FullPathWithFileName = Path.Combine(sPath, fileName);
                            using (var stream = new FileStream(FullPathWithFileName, FileMode.Create))
                            {
                                await Attachment.CopyToAsync(stream);
                            }
                        }
                    }
                    Activity activityObj = _context.Activity.Find(activityDetail.ActivityID);
                    activityObj.ActualCost = ActualCost;
                    //_context.Update(activityObj);
                    _context.Update(activityDetail);
                    await _context.SaveChangesAsync();

                    if (activityDetail.StepID == 21)
                    {
                        ActivityDetailWork Obj = _context.ActivityDetailWork.Where(a => a.ActivityID == activityDetail.ActivityID).FirstOrDefault();
                        Obj.ContractorID = CID;
                        Obj.ExpiryDate   = ExpiryDate;
                        _context.Update(Obj);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Edit), new { activityDetail.ActivityID, activityDetail.StepID }));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActivityDetailExists(activityDetail.ActivityID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (activityDetail.StepID == 8)
                {
                    return(RedirectToAction(nameof(Edit), new { activityDetail.ActivityID, activityDetail.StepID }));
                }
                else
                {
                    return(RedirectToAction(nameof(Edit), "Activities", new { id = activityDetail.ActivityID }));
                }
            }
            ViewData["ActivityID"] = new SelectList(_context.Activity, "ActivityID", "Description", activityDetail.ActivityID);
            ViewData["StepID"]     = new SelectList(_context.Step, "StepID", "StepID", activityDetail.StepID);
            return(View(activityDetail));
        }