public async Task <IActionResult> Create([Bind("UserWorkId,AppUserId,DatePosting,UserWorkName,UserWorkDescription,UserWorkTypeId")] UserWork userWork, IFormFile uploadedFile) { if (ModelState.IsValid) { if (uploadedFile != null) { var loadedFile = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Работа пользователя", FileDataTypeEnum.UserWork); if (loadedFile != null) { userWork.FileModelId = loadedFile.Id; } } _context.Add(userWork); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var currentUser = await _context.Users.SingleOrDefaultAsync(u => u.UserName == User.Identity.Name); if (currentUser == null) { return(RedirectToAction(nameof(Index))); } ViewData["AppUserId"] = currentUser.Id; ViewData["UserWorkTypeId"] = new SelectList(_context.UserWorkTypes, "UserWorkTypeId", "UserWorkTypeName", userWork.UserWorkTypeId); return(View(userWork)); }
public UserWorkModel Hire(int userId, int workId, decimal rate) { var userWork = new UserWork { DateFrom = DateTime.Now, Active = true, UserId = userId, UserRate = rate, WorkId = workId }; _repositoryManager.UserWorks.Add(userWork); _repositoryManager.UserWorks.SaveChanges(); return(new UserWorkModel { Id = userWork.Id, DateFrom = userWork.DateFrom, DateTo = null, TotalEarned = 0, UserId = userWork.UserId ?? 0, UserRate = userWork.UserRate, WorkId = userWork.WorkId ?? 0 }); }
private void bgUserWorks_DoWork(object sender, DoWorkEventArgs e) { var isStart = (bool)e.Argument; var result = new UserWorksResult(); result.IsStart = isStart; result.Now = DateTime.Now; try { if (isStart) { userWork = new UserWork() { Username = txtUsername.Text, Title = txtTitle.Text, }; userWork.ID = UserWorks.StartTime(userWork.Username, userWork.Title); } else { UserWorks.EndTime(userWork.ID); } } catch (Exception ex) { result.IsError = true; result.Error = ex.Message; } e.Result = result; }
public ActionResult DeleteConfirmed(int id) { UserWork userWork = db.UserWorks.Find(id); db.UserWorks.Remove(userWork); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteWork(int id) { UserWork userWorks = new UserWork(); userWorks.DeleteWork(id); var data = userWorks.GetUsersWorks(); return(PartialView(data)); }
public int StartTime(string username, string title) { UserWork userWork = new UserWork(); userWork.Username = username; userWork.Title = title; userWork.StartTime = DateTime.Now; UserWorks.Insert(userWork); return(userWork.ID); }
public ActionResult Create(UserWork userWork) { if (ModelState.IsValid) { userWork.CreationDate = DateTime.Now; userWork.LastModificationDate = DateTime.Now; db.UserWorks.Add(userWork); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userWork)); }
// GET: UserWorks/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UserWork userWork = db.UserWorks.Find(id); if (userWork == null) { return(HttpNotFound()); } return(View(userWork)); }
// DELETE: odata/UserWorks(5) public IHttpActionResult Delete([FromODataUri] int key) { UserWork userWork = db.UserWorks.Find(key); if (userWork == null) { return(NotFound()); } db.UserWorks.Remove(userWork); db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public UserWork AssignWork(Work work, List <User> users) { var userWork = new UserWork(); foreach (var user in users) { work.StateId = Convert.ToInt32(Work.State.New); userWork.UserId = user.Id; userWork.WorkId = work.Id; _userWorkDal.Add(MapperHelper.MapToSameType(_userWorkDal.Add(userWork))); } return(MapperHelper.MapToSameType(userWork)); }
public ActionResult Contacts(string name, string email, string tel, string message, IEnumerable <HttpPostedFileBase> uploads) { Category category = new Category(); ViewBag.Category = category.GetCategories(); ViewBag.Message = "Your contact page."; ViewBag.ActiveContact = "nav__link--current"; UserWork userWork = new UserWork(); userWork.AddWork(name, email, tel, message, uploads); return(View()); }
// GET: AdminUsersWorks public ActionResult Index(int?page) { Category category = new Category(); ViewBag.Category = category.GetCategories(); UserWork userWorks = new UserWork(); var data = userWorks.GetUsersWorks(); int pageSize = 10; int pageNumber = (page ?? 1); return(View(data.ToPagedList(pageNumber, pageSize))); }
// POST: odata/UserWorks public IHttpActionResult Post(UserWork userWork) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } userWork.CreationDate = DateTime.Now; userWork.LastModificationDate = DateTime.Now; //userWork.Creator = core.getCurrentUser(); //userWork.Modifier = core.getCurrentUser(); db.UserWorks.Add(userWork); db.SaveChanges(); return(Created(userWork)); }
public ActionResult Edit(UserWork userWork) { if (ModelState.IsValid) { UserWork origin = db.UserWorks.Where(y => y.id == userWork.id).First(); origin.Name = userWork.Name; origin.AdjectiveName = userWork.AdjectiveName; origin.Enabled = userWork.Enabled; origin.LastModificationDate = DateTime.Now; origin.Code = userWork.Code; db.Entry(origin).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userWork)); }
public async Task <IActionResult> Edit(int id, [Bind("UserWorkId,AppUserId,DatePosting,UserWorkName,UserWorkDescription,UserWorkTypeId,FileModelId")] UserWork userWork, IFormFile uploadedFile) { if (id != userWork.UserWorkId) { return(NotFound()); } if (ModelState.IsValid) { try { if (uploadedFile != null) { var loadedFile = await KisVuzDotNetCore2.Models.Files.Files.LoadFile(_context, _appEnvironment, uploadedFile, "Работа пользователя", FileDataTypeEnum.UserWork); await _context.SaveChangesAsync(); var fileToRemoveId = userWork.FileModelId; userWork.FileModelId = loadedFile.Id; await _context.SaveChangesAsync(); KisVuzDotNetCore2.Models.Files.Files.RemoveFile(_context, _appEnvironment, fileToRemoveId); } _context.Update(userWork); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserWorkExists(userWork.UserWorkId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AppUserId"] = new SelectList(_context.Users, "Id", "Id", userWork.AppUserId); ViewData["FileModelId"] = new SelectList(_context.Files, "Id", "Id", userWork.FileModelId); ViewData["UserWorkTypeId"] = new SelectList(_context.UserWorkTypes, "UserWorkTypeId", "UserWorkTypeId", userWork.UserWorkTypeId); return(View(userWork)); }
// PUT: odata/UserWorks(5) public IHttpActionResult Put([FromODataUri] int key, Delta <UserWork> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } UserWork userWork = db.UserWorks.Find(key); if (userWork == null) { return(NotFound()); } patch.Put(userWork); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserWorkExists(key)) { return(NotFound()); } else { throw; } } return(Updated(userWork)); }
public static TagA UserWorkLink(this HtmlHelper helper, UserWork w) { return(new UrlHelper(helper.ViewContext.RequestContext).Link <ClientController>( sc => sc.UserWorks(w.Section_ID, w.WorkSectionID.GetValueOrDefault(), 1), Images.Image("UserWork/Small/" + w.SmallImage).Title("Перейти на страницу работ слушателей").Width(170))); }
// POST: odata/Services public IHttpActionResult Post(Service Service) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Get Service Path if (!Service.ServicePathId.Equals(null)) { ServicePath path = db.ServicePaths.Find(Service.ServicePathId); if (path == null) { core.throwExcetpion("No Matching Service Path"); } Service.ServicePath = path; } //Get Service user work if (!Service.UserWorkId.Equals(null)) { UserWork work = db.UserWorks.Find(Service.UserWorkId); if (work == null) { core.throwExcetpion("No Matching UserWork!"); } Service.UserWork = work; } //Get Service Provider if (!Service.ServiceProviderId.Equals(null)) { ApplicationUser serviceProvider = db.Users.Find(Service.ServiceProviderId); if (serviceProvider == null) { core.throwExcetpion("No Matching Service Provider"); } Service.ServiceProvider = serviceProvider; } //Check Private Service Price if (Service.PrivateService) { if (Service.PrivateServicePrice.Equals(null)) { core.throwExcetpion("Private service price can't be null!"); } } ApplicationUser currentUser = core.getCurrentUser(); Service.Status = CoreController.ServiceStatus.Active.ToString(); Service.CreationDate = DateTime.Now; Service.LastModificationDate = DateTime.Now; Service.ServiceProviderNewDate = DateTime.Now; Service.CreatorId = core.getCurrentUser().Id; Service.ModifierId = core.getCurrentUser().Id; //Service.Creator = core.getCurrentUser(); //Service.Modifier = core.getCurrentUser(); db.Services.Add(Service); addComment(Service.id, Service.ServiceProviderId, Service.ServicePathId); db.SaveChanges(); return(Created(Service)); }