// POST: api/AlfaCapital public IHttpActionResult Post(AlfaCapital call) { log.Debug("Add new call: " + call.ToString()); if (call == null) { log.Error("Call is empty"); return(BadRequest()); } if (!ModelState.IsValid) { log.Error("Call is not valid"); return(BadRequest(ModelState)); } try { call.DateTransferContact = DateTime.Now; db.AlfaCapitals.Add(call); db.SaveChanges(); return(Ok(call.Id)); } catch (Exception ex) { log.Error(ex); return(BadRequest()); } }
// PUT api/values/5 /// <summary> /// /// </summary> /// <param name="user"></param> /// <returns></returns> public IHttpActionResult Post(Cofactor2User user) { if (user == null) { Log.Error("user is empty"); return(BadRequest()); } Log.Debug("update user: "******"user.Id"); if (user.firstname != null) { dbUser.firstname = user.firstname; } if (user.email != null) { dbUser.email = user.email; } if (user.patronymic != null) { dbUser.patronymic = user.patronymic; } if (user.lastname != null) { dbUser.lastname = user.lastname; } if (user.phone != null) { dbUser.phone = user.phone; } if (!ModelState.IsValid) { Log.Error("user is not valid"); return(BadRequest(ModelState)); } _db.SaveChanges(); return(Ok()); } Log.Error("user not found"); return(BadRequest("user not found")); } catch (Exception ex) { Log.Error(ex); return(BadRequest()); } }
public JsonResponse Publish(CofactorStatRequest stat) { log.Debug("Request post user stat. Stat is " + JsonConvert.SerializeObject(stat)); try { Guid uid = stat.uid; var user = db.CofactorUsers.FirstOrDefault(r => r.uid == uid); if (user != null) { var dbStat = db.CofactorStats.FirstOrDefault(r => r.uid == uid && r.prid == stat.prid); if (dbStat == null) { dbStat = new CofactorStat(); db.CofactorStats.Add(dbStat); } dbStat.created = DateTime.Now; dbStat.uid = uid; dbStat.prid = stat.prid; dbStat.duration = stat.duration; dbStat.data = JsonConvert.SerializeObject(stat.data); db.SaveChanges(); } else { return new JsonResponse() { status = 404 } }; } catch (Exception ex) { log.Error(ex); return(new JsonResponse() { status = 400 }); } return(new JsonResponse() { status = 200 }); }