Esempio n. 1
0
        public ActionResult Danhgiacongviec(string submitButton, FormCollection collection)
        {
            var idDoi    = collection["teamID"];
            var idCV     = collection["jobID"];
            var idCD     = collection["campaignID"];
            var result   = collection["jobResult"];
            var pictures = collection["jobPictures"];



            switch (submitButton)
            {
            case "Add":
                if (ModelState.IsValid)
                {
                    ViewBag.ThongBao = pictures;
                    CTCONGVIEC ctcv = db.CTCONGVIECs.FirstOrDefault(n => n.IdCV == idCV);
                    ctcv.KetQuaCV = result == "Hoàn thành" ? '1' : '0';
                    ctcv.HinhAnh  = pictures;

                    UpdateModel(ctcv);
                    db.SubmitChanges();
                }
                return(RedirectToAction("Danhgiacongviec"));

            case "Edit":
                CTCONGVIEC ctcvedit = db.CTCONGVIECs.FirstOrDefault(n => n.IdCV == idCV);

                if (ModelState.IsValid)
                {
                    ctcvedit.KetQuaCV = result == "Hoàn thành" ? '1' : '0';
                    ctcvedit.HinhAnh  = pictures;

                    UpdateModel(ctcvedit);
                    db.SubmitChanges();
                }
                return(RedirectToAction("Danhgiacongviec"));

            case "Delete":
                CTCONGVIEC ctcvdel = db.CTCONGVIECs.FirstOrDefault(n => n.IdCV == idCV);

                db.CTCONGVIECs.DeleteOnSubmit(ctcvdel);
                db.SubmitChanges();
                return(RedirectToAction("Danhgiacongviec"));

            default:
                return(RedirectToAction("Danhgiacongviec"));
            }
        }
Esempio n. 2
0
        public ActionResult QLCongviec(string submitButton, string showButton, CONGVIEC congviec, FormCollection collection)
        {
            var id          = collection["jobID"];
            var idCD        = collection["campaignID"];
            var name        = collection["jobName"];
            var place       = collection["jobPlace"];
            var detail      = collection["jobDetails"];
            var pneed       = collection["jobPneeded"];
            var reservation = collection["reservation"];
            var startday    = reservation.Split('-')[0];
            var endday      = reservation.Split('-')[1];
            var time        = DateTime.Parse(endday) - DateTime.Parse(startday);
            var cost        = collection["jobCost"];
            var moreinfo    = collection["jobMoreinfo"];
            var numofteam   = (int)(int.Parse(pneed) / 10);
            var totalFee    = (float)(int.Parse(pneed) * float.Parse(cost));

            switch (submitButton)
            {
            case "Add":
                if (ModelState.IsValid)
                {
                    congviec.Id             = id;
                    congviec.IdCD           = idCD;
                    congviec.TenCV          = name;
                    congviec.DiaDiem        = place;
                    congviec.SoLuongNguoi   = int.Parse(pneed);
                    congviec.NgayBatDau     = DateTime.Parse(startday);
                    congviec.ThoiGian       = time.Days;
                    congviec.ChiPhiMotNguoi = decimal.Parse(cost);
                    congviec.MoreInfo       = moreinfo;
                    congviec.NoiDung        = detail;

                    db.CONGVIECs.InsertOnSubmit(congviec);
                    db.SubmitChanges();


                    for (int i = 1; i <= numofteam; i++)
                    {
                        DOI doi = new DOI();
                        doi.Id   = id + "-" + i.ToString();
                        doi.IdCD = idCD;
                        doi.SoLuongThanhVienThamGia = 0;
                        if (i == numofteam)
                        {
                            doi.SoLuongThanhVien = int.Parse(pneed) - (10 * numofteam) + 10;
                        }
                        else
                        {
                            doi.SoLuongThanhVien = 10;
                        }
                        db.DOIs.InsertOnSubmit(doi);
                        db.SubmitChanges();

                        CTCONGVIEC ctcv = new CTCONGVIEC();
                        ctcv.IdCV     = id;
                        ctcv.IdDoi    = id + "-" + i.ToString();
                        ctcv.KetQuaCV = '0';
                        db.CTCONGVIECs.InsertOnSubmit(ctcv);
                        db.SubmitChanges();
                    }

                    PHIEUTHANHTOAN ptt = db.PHIEUTHANHTOANs.FirstOrDefault(n => n.IdCD == idCD);
                    ptt.ChiPhiDuDinh += totalFee;
                    ptt.TongChiPhi    = ptt.ChiPhiDuDinh + ptt.CHiPhiPhatSinh;
                    UpdateModel(ptt);
                    db.SubmitChanges();
                }
                return(RedirectToAction("QLCongviec"));

            case "Edit":
                var cv = db.CONGVIECs.SingleOrDefault(n => n.Id == id);
                if (ModelState.IsValid)
                {
                    cv.IdCD           = idCD;
                    cv.TenCV          = name;
                    cv.DiaDiem        = place;
                    cv.SoLuongNguoi   = int.Parse(pneed);
                    cv.NgayBatDau     = DateTime.Parse(startday);
                    cv.ThoiGian       = time.Days;
                    cv.ChiPhiMotNguoi = decimal.Parse(cost);
                    cv.MoreInfo       = moreinfo;
                    cv.NoiDung        = detail;


                    UpdateModel(cv);
                    db.SubmitChanges();
                }
                return(RedirectToAction("QLCongviec"));

            case "Delete":
                var cvDel = db.CONGVIECs.SingleOrDefault(n => n.Id == id);
                db.CONGVIECs.DeleteOnSubmit(cvDel);
                db.SubmitChanges();
                return(RedirectToAction("QLCongviec"));

            default:
                return(RedirectToAction("QLCongviec"));
            }
        }