public async Task <IActionResult> LeaveStar(StarModel model) { var user = await _userManager.FindByEmailAsync(model.AuthorId); var str = ctx.Stars.SingleOrDefault(s => s.AuthorId == user.Id && s.InstrumentId == model.InstrumentId); if (str != null) { str.Mark = model.Mark; } else { ctx.Stars.Add( new Star() { AuthorId = user.Id, InstrumentId = model.InstrumentId, Mark = model.Mark } ); } await ctx.SaveChangesAsync(); return(Ok(new StarResult() { Successful = true })); }
public async Task <Result> AddService(AddOrgModel model) { var user = await _userManager.FindByEmailAsync(model.OwnersEmail); switch (model.Type) { case "Service": await _userManager.AddToRoleAsync(user, "ServiceAdmin"); var service = new Service() { CreationDate = DateTime.Now }; ctx.Services.Add(service); await ctx.SaveChangesAsync(); ctx.ServiceUsers.Add( new ServiceUser() { ServiceId = service.Id, UserId = user.Id } ); break; case "Company": await _userManager.AddToRoleAsync(user, "CompanyAdmin"); var company = new Company() { CreationDate = DateTime.Now }; ctx.Companies.Add(company); await ctx.SaveChangesAsync(); ctx.CompanyUsers.Add( new CompanyUser() { CompanyId = company.Id, UserId = user.Id } ); break; } await ctx.SaveChangesAsync(); return(new Result() { Successful = true }); //TODO constraints }
public async Task <IActionResult> DeleteGood(DeleteGoodModel m) { var instrument = new Instrument { Id = m.Id }; ctx.Instruments.Attach(instrument); ctx.Instruments.Remove(instrument); await ctx.SaveChangesAsync(); return(Ok()); }
public async Task <AddMessageResult> AddMessage(AddMessageModel model) { var mes = _mapper.Map <Message>(model); mes.Date = DateTime.Now; var email = User.Identity.Name; var user = await _userManager.FindByEmailAsync(email); mes.UserId = user.Id; ctx.Messages.Add(mes); await ctx.SaveChangesAsync(); return(new AddMessageResult() { Success = true }); }
public async Task <IActionResult> LeaveCommentSample(CommentModel model) { var user = await _userManager.FindByEmailAsync(model.AuthorId); ctx.Comments.Add( new Comment() { InstrumentId = model.InstrumentId, Text = model.Text, Date = DateTime.Now, User = user } ); await ctx.SaveChangesAsync(); return(Ok(new LeaveCommentResult() { Successful = true })); }
public async Task <Result> AddWorkerToOrder(AddWorkerToOrderModel model) { var orderworker = _mapper.Map <OrderWorker>(model); await ctx.OrderWorkers.AddAsync(orderworker); await ctx.SaveChangesAsync(); return(new Result() { Successful = true }); }
public async Task <Result> AddReview(AddReviewModel model) { var r = _mapper.Map <Review>(model); var user = await _userManager.FindByEmailAsync(User.Identity.Name); r.UserId = user.Id; r.CompanyId = ctx.CompanyUsers.Single(cu => cu.UserId == user.Id).CompanyId; ctx.Reviews.Add(r); await ctx.SaveChangesAsync(); return(new Result() { Successful = true }); }
public async Task <Result> EditLocation(LocationViewModel model) { var location = ctx.Locations.Single(l => l.Id == model.Id); location.Address = model.Address; location.Description = model.Description = model.Description; location.Name = model.Name; location.Image = await SaveAndGetLocalFilePathIfNewerPhoto(model.PictureModel); await ctx.SaveChangesAsync(); return(new Result() { Successful = true }); }