public async Task <IActionResult> Create(TeamIM team) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } try { var model = _mapper.Map <Team>(team); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; _context.Add(model); await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Team)); return(Json(AR)); } catch (Exception er) { AR.Setfailure(er.Message); return(Json(AR)); } }
public async Task <IActionResult> Create(RecipeIM im) { if (ModelState.IsValid) { var user = await _context.Users.FirstOrDefaultAsync(d => d.UserName == User.Identity.Name); var model = new Recipe { Title = im.Title, CustomerMobile = im.CustomerMobile, CreatedDate = DateTime.Now, Description = im.Description, UserId = user.Id }; foreach (var item in im.RecipeItems) { model.RecipesItems.Add(new RecipesItem { ProductId = item.ProductId, Quantity = item.Quantity }); } _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(MyRecipes))); } return(View(im)); }
public async Task <IActionResult> Create(PostIM post) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } try { var model = _mapper.Map <Post>(post); model.CreatedBy = User.Identity.Name; model.CreatedDate = DateTime.Now; //model.Body = WebUtility.HtmlEncode(page.Body); _context.Add(model); await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Post)); return(Json(AR)); } catch (Exception er) { AR.Setfailure(er.Message); return(Json(AR)); } }
public async Task <IActionResult> Create([Bind("Id,Name,Thumbnail,Contact,Phone,Address,Province,City,District,Coordinate,Body")] StoreIM store) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } var model = _mapper.Map <Store>(store); if (!string.IsNullOrEmpty(store.Coordinate) && store.Coordinate.Contains(",")) { var cod = store.Coordinate.Split(","); decimal.TryParse(cod[0], out decimal lng); decimal.TryParse(cod[1], out decimal lat); model.Longitude = lng; model.Latitude = lat; } _context.Add(model); await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Store)); return(Json(AR)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,Importance,Active")] PostCategoryIM im) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR)); } var model = _mapper.Map <PostCategory>(im); model.CreatedDate = DateTime.Now; model.CreatedBy = User.Identity.Name; _context.Add(model); await _context.SaveChangesAsync(); AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.PostCategory)); return(Json(AR)); }