public async Task <IHttpActionResult> Put(InternShip data)
        {
            string methodNameStr = $"InternShipController().Put({data})";

            try
            {
                logger.Log(LogLevel.Info, $"{MakeLogStr4Entry(methodNameStr)}.");
                using (var context = new SampDB())
                {
                    var repos = new GenericDataRepository(context);
                    var res   = await repos.UpdateAsync <InternShip>(data);

                    if (res == HttpStatusCode.OK)
                    {
                        await context.SaveChangesAsync();
                    }
                    logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} {res}");
                    return(Content(res, res.ToString()));
                }
            }
            catch (Exception e)
            {
                logger.Log(LogLevel.Error, $"{MakeLogStr4Exit(methodNameStr)}:\r\n{e}");
                return(Content(HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString()));
            }
        }
 public bool CreateInternShip(InternShip ish)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         InternShip          i        = new InternShip();
         i.InternshipID = database.InternShip.Count() + 1;
         i.CourseName   = ish.CourseName;
         i.Note         = ish.Note;
         i.StartDay     = ish.StartDay;
         i.ExpiryDate   = ish.ExpiryDate;
         i.Status       = false;
         i.CompanyID    = Session["CompanyID"].ToString();
         var ro = Convert.ToInt32(Session["Role"]);
         if (ish.PersonID != null)
         {
             i.PersonID = ish.PersonID;
         }
         else if (ro == 4)
         {
             var pid = Session["Person"].ToString();
             i.PersonID = pid;
         }
         database.InternShip.Add(i);
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public ActionResult Create(InternShip ish)
        {
            InternShip i = new InternShip();

            i.InternshipID = database.InternShip.Count() + 1;
            i.CourseName   = ish.CourseName;
            i.Note         = ish.Note;
            i.StartDay     = ish.StartDay;
            i.ExpiryDate   = ish.ExpiryDate;
            i.Status       = false;
            i.CompanyID    = Session["CompanyID"].ToString();
            var ro = Convert.ToInt32(Session["Role"]);

            if (ish.PersonID != null)
            {
                i.PersonID = ish.PersonID;
            }
            else if (ro == 4)
            {
                var pid = Session["Person"].ToString();
                i.PersonID = pid;
            }
            database.InternShip.Add(i);
            database.SaveChanges();
            ModelState.AddModelError("", "Thành công");
            SetViewBagL();
            SetViewBagM();
            return(View("Create"));
        }
 public ActionResult Create(InternShip ish)
 {
     if (ModelState.IsValid)
     {
         if (CreateInternShip(ish))
         {
             ModelState.AddModelError("", "Thêm Khóa học thành công");
         }
         else
         {
             ModelState.AddModelError("", "Thêm Khóa học thất bại");
         }
     }
     SetViewBagL();
     SetViewBagM();
     return(View("Create"));
 }
 public ActionResult Edit(InternShip ish)
 {
     if (ModelState.IsValid)
     {
         if (EditInterShip(ish))
         {
             ModelState.AddModelError("", "Cập nhật Khóa học thành công");
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật Khóa học thất bại");
         }
     }
     SetViewBagL();
     SetViewBagM();
     Session["InternshipID"] = ish.InternshipID;
     return(View("Edit"));
 }
        public ActionResult Edit(InternShip ish)
        {
            var i = database.InternShip.Find(ish.InternshipID);

            i.CourseName = ish.CourseName;
            i.Note       = ish.Note;
            i.StartDay   = ish.StartDay;
            i.ExpiryDate = ish.ExpiryDate;
            if (ish.PersonID != null)
            {
                i.PersonID = ish.PersonID;
            }
            database.SaveChanges();
            SetViewBagL();
            SetViewBagM();
            ModelState.AddModelError("", "Thành công");
            return(View("Edit"));
        }
Beispiel #7
0
        public ActionResult AddInternShip([FromBody] InternShipRequest req)
        {
            if (req != null)
            {
                var internShip = new InternShip()
                {
                    finishDate = req.finishDate,
                    startDate  = req.startDate,
                    studentId  = req.studentId
                };
                _appRepository.Add(internShip);
                _appRepository.SaveAll();
                _appRepository.createDays(req);
                return(StatusCode(201));
            }

            return(null);
        }
 public bool EditInterShip(InternShip ish)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var i = database.InternShip.Find(ish.InternshipID);
         i.CourseName = ish.CourseName;
         i.Note       = ish.Note;
         i.StartDay   = ish.StartDay;
         i.ExpiryDate = ish.ExpiryDate;
         if (ish.PersonID != null)
         {
             i.PersonID = ish.PersonID;
         }
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }