コード例 #1
0
 public IHttpActionResult Post(CourseTypeMaster model)
 {
     try
     {
         bool isExist = db.CourseTypeMasters.Any(x => x.Name == model.Name.Trim());
         if (isExist)
         {
             return(BadRequest(Message.AlreadyExist));
         }
         model.Name = model.Name.Trim();
         db.CourseTypeMasters.Add(model);
         db.SaveChanges();
         string output = JsonConvert.SerializeObject(model);
         return(Ok(new ResponseViewModel(Message.Add, HttpStatusCode.OK, output)));
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
 public IHttpActionResult Put(int id, CourseTypeMaster model)
 {
     try
     {
         bool isExist = db.CourseTypeMasters.Any(x => x.Name == model.Name.Trim() && x.CourseTypeId != id);
         if (isExist)
         {
             return(BadRequest(Message.AlreadyExist));
         }
         var courseMaster = db.CourseTypeMasters.Where(x => x.CourseTypeId == id).FirstOrDefault();
         model.Name        = model.Name.Trim();
         model.Status      = 1;
         courseMaster.Name = model.Name;
         // db.TaggingMasters.Add(model);
         db.SaveChanges();
         string output = JsonConvert.SerializeObject(model);
         return(Ok(new ResponseViewModel(Message.Updated, HttpStatusCode.OK, output)));
     }
     catch (Exception e)
     {
         throw;
     }
 }