Пример #1
0
        public IHttpActionResult CreateNote([FromBody] TradeNoteAddBindingModel Model)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest("invalid data."));
            }
            if (Model == null)
            {
                return(BadRequest("any information about Note was specified"));
            }
            else
            {
                Company Company = TradeNoteContext.Companies.SingleOrDefault(c => c.Id == Model.CompanyId);
                if (Company == null || Company.IsDeleted == true)
                {
                    return(BadRequest("The company with this request doesn't exist"));
                }

                TradeNote NewNote = new TradeNote();
                NewNote.Text      = Model.Text;
                NewNote.CompanyId = Company;

                string          UserId  = User.Identity.GetUserId();
                ApplicationUser AppUser = TradeNoteContext.Users.Single(u => u.Id == UserId);
                NewNote.UserId = AppUser;
                TradeNoteContext.TradeNotes.Add(NewNote);
                TradeNoteContext.SaveChanges();
                return(Ok(NewNote));
            }
        }
Пример #2
0
        public ActionResult CreateTradeNote(TradeNoteAddBindingModel NewTradeNote)
        {
            var postTask = ApiHelper.ApiClient.PostAsJsonAsync <TradeNoteAddBindingModel>("api/TradeNote", NewTradeNote);

            postTask.Wait();

            var result = postTask.Result;

            if (result.IsSuccessStatusCode)
            {
                //Coś z tym trza zrobić !!
                return(RedirectToAction("TradeNotes"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                return(View("NewCompany"));// z tym coś trzeba zrobić
            }
        }