/// <summary> /// Добавление нового аккаунта /// </summary> /// <param name="name">Ник</param> /// <param name="email">Email</param> /// <returns></returns> public IActionResult AddingNewAccount(string name, string email) { using (AppDb db = new AppDb()) { var r = db.Profiles.Where(p => p.Account.Email == email).FirstOrDefault(); if (r == null) { Account acc = new Account(name, email); db.Add(acc); Department depart = new Department(); db.Add(depart); Profile prof = new Profile(depart, acc); db.Add(prof); db.SaveChanges(); var t = db.Profiles.Where(p => p.Account.Email == email).FirstOrDefault(); int depid = t.DepartmentId; return(RedirectToAction("NewProfile", "Home", new { name = name, email = email, depid = depid })); } else { return(RedirectToAction("ErrorEmail", "Home")); } } }
public ActionResult Post([FromBody] CashInOut cash) { try { var credit = db.CashInOut.Where(x => x.transacionType == 2).Sum(x => x.Amount); var debit = db.CashInOut.Where(x => x.transacionType == 1).Sum(x => x.Amount); if (cash.transacionType == 1) { debit += cash.Amount; } else { credit += cash.Amount; } cash.RunningBalance = credit - debit; cash.dtCreated = DateTime.Now; db.Add(cash); db.SaveChanges(); return(Ok()); } catch (Exception) { throw; } }
public IActionResult Post([FromBody] VehicleCreateDto model) { var vehicle = _mapper.Map <Vehicle>(model); vehicle.AccountId = _userService.CurrentUserId; _db.Add(vehicle); _db.SaveChanges(); return(Created("", model)); }
public ActionResult <Todos> Post([FromBody] Todos todo) { _appdb.Add(todo); todo.status = "Progress"; todo.createdat = DateTime.Now; todo.publishedat = DateTime.Now; _appdb.SaveChanges(); return(todo); }
public async Task <IActionResult> Create([Bind("CustomerID,CustomerName")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <IActionResult> Create([Bind("SeasonID,SeasonName,StartDate,EndDate")] Season season) { if (ModelState.IsValid) { _context.Add(season); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(season)); }
public void SetPerson() { for (int i = 1; i <= 35; i++) { Person person = new Person { Name = $"Person{i}" }; db.Add(person); db.SaveChanges(); } }
// public int CurrentUserId // { // get // { // if (!EnumerableExtensions.Any(_db.Accounts)) // { // _db.Add(new Account {Telephone = "911"}); // _db.SaveChanges(); // } // // return _db.Accounts.First().Id; // } // private set { }; // } public void SetCurrentUser(string phone) { if (!_db.Accounts.Any(x => x.Telephone == phone)) { _db.Add(new Account { Telephone = phone }); _db.SaveChanges(); } CurrentUserId = _db.Accounts.First(x => x.Telephone == phone).Id; }
public ActionResult <RoomType> Create(RoomTypeRequest item) { var roomType = new RoomType(); roomType.Code = item.Code.ToUpper(); roomType.Name = item.Name; roomType.Price = item.UnitPrice; db.Add(roomType); db.SaveChanges(); return(CreatedAtAction(nameof(GetByCode), new { code = roomType.Code }, roomType)); }
//private void AddVisits() //{ // var items = db.Patients.ToList(); // foreach (var item in items) // { // var v = new Visit(); // v.AN = item.HN + "00"; // v.AdmissionDate = DateTime.Today; // item.Visits.Add(v); // } // db.SaveChanges(); //} private void AddPatient() { var p = new Patient(); p.HN = $"11222{DateTime.Now.Millisecond:000}"; p.FirstName = "First"; p.LastName = "last"; p.Birthdate = DateTime.Today.AddYears(-40); p.Sex = Sex.Male; p.Phone = "999"; db.Add(p); db.SaveChanges(); }
public ActionResult Post([FromBody] FuelCreateDto model) { if (!_db.Vehicles.Any(x => x.Id == model.VehicleId && x.Account.Id == _userService.CurrentUserId)) { return(BadRequest()); } var fuel = _mapper.Map <Fuel>(model); fuel.CalculatePricePerLitre(); _db.Add(fuel); _db.SaveChanges(); CalculateFuelConsumption(fuel); return(Created("", model)); }
public ActionResult Post([FromBody] FeedVM model) { //Console.WriteLine($"url: {model.Url} with source: {model.Source}"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var feed = new Feed { FeedUrl = model.FeedUrl, Website = model.Website, Name = model.Name }; _db.Add(feed); _db.SaveChanges(); _updater.UpdateFeed(feed); return(Created("", model)); }
public ActionResult <RoomResponse> Create(RoomRequest item) { var itemRoomType = db.RoomTypes.Find(item.RoomType); if (itemRoomType == null) { return(NotFound(new ProblemDetails() { Title = $"RoomType code : {item.RoomType} not found" })); } Room newRoom = item.ToModel(); db.Add(newRoom); db.SaveChanges(); return(CreatedAtAction(nameof(GetById), new { id = newRoom.Id }, RoomResponse.FromModel(newRoom))); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,ImageUrl,Comment")] Product product) { if (product.Name == "xxx") { ModelState.AddModelError(nameof(Product.Name), "This name is not allowd"); } if (ModelState.IsValid) { //product.Id = Guid.NewGuid(); _context.Add(product); // _context.Products.Add(product); await _context.SaveChangesAsync(); var newId = product.Id; TempData["NewId"] = newId; return(RedirectToAction(nameof(Index))); } return(View(product)); }
public IActionResult Create(Product item, IFormFile[] pics) // create object --> assign properties from request data --> validation in ModelState { if (db.Products.Any(x => x.Name == item.Name)) { ModelState.AddModelError(nameof(Product.Name), "Duplicate name."); } if (ModelState.IsValid) { foreach (var pic in pics) { string fileName = Path.GetRandomFileName() + Path.GetExtension(pic.FileName); string filePath = Path.Combine(env.ContentRootPath, "Files", fileName); using (FileStream fs = new FileStream(filePath, FileMode.CreateNew)) { pic.CopyTo(fs); } ProductPicture productPicture = new ProductPicture { Description = "", Url = fileName, }; item.Pictures.Add(productPicture); } item.CreateDate = DateTime.UtcNow.AddHours(7); db.Add(item); // db.Products.Add(product); // in memory int rowAffected = db.SaveChanges(); // create SQL, execute at server-side. TempData["NewId"] = item.Id; return(RedirectToAction(nameof(Index))); } return(View(item)); }
public bool AddPerson(Person model) { _context.Add(model); return(_context.SaveChanges() > 0); }