private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { MessageBox.Show("Введите название проекта", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { ProjectBindingModel model = new ProjectBindingModel { Name = textBoxName.Text, Deadline = dateTimePicker.Value }; if (Id.HasValue) { model.Id = Id; } _logicP.CreateOrUpdate(model); MessageBox.Show("Успешно", "Сохранено", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task <IActionResult> EditProject(int id) { var project = await DbContext.Projects.Include(a => a.Images).SingleOrDefaultAsync(i => i.Id == id); var projectDto = new ProjectBindingModel { ProjectModel = new EditProjectBindingModel { Id = project.Id, Number = project.Number, Name = project.Name, Subname = project.Subname, About = project.About, //Image550X365 = project.Image550X365, //Image450X398 = project.Image450X398, //Image400X354 = project.Image400X354, //Image1280X478 = project.Image1280X478, }, Images = project.Images.Select(i => new Image { Name = i.Name, About = i.About, Link = i.Link }).ToList() }; return(View("EditProject", projectDto)); }
public ProjectViewModel Add(string userId, ProjectBindingModel model) { var user = this.data.UserRepository.GetById(userId); if (!user.isAdmin) { throw new InvalidOperationException(Constants.NotAdmin); } var project = mapper.Map <ProjectBindingModel, Project>(model); var leadUser = this.data.UserRepository.GetById(model.LeadId); if (leadUser == null) { throw new ArgumentException(Constants.UnexistingUserErrorMessage); } project.Lead = leadUser; AddTransitionScheme(model.TransitionSchemeId, project); if (model.Labels != null) { AddLabels(model.Labels, project); } AddPriorities(model.Priorities, project); this.data.ProjectRepository.Insert(project); this.data.Save(); return(GetMappedProject(project)); }
public IHttpActionResult Add(ProjectBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = RequestContext.Principal.Identity.GetUserId(); var project = this.projectsService.Add(userId, model); return(CreatedAtRoute("GetProjectById", new { id = project.Id }, project)); }
public void Delete(ProjectBindingModel model) { var element = _projectStorage.GetElement(new ProjectBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Проект не найден"); } _projectStorage.Delete(model); }
public List <ProjectViewModel> Read(ProjectBindingModel model) { if (model == null) { return(_projectStorage.GetFullList()); } if (model.Id.HasValue) { return(new List <ProjectViewModel> { _projectStorage.GetElement(model) }); } return(_projectStorage.GetFilteredList(model)); }
public async Task <IHttpActionResult> CreateProject(ProjectBindingModel projectModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Project project = new Project(); Mapper.Map(projectModel, project); var result = await _projectService.CreateAsync(project); return(Ok(project)); }
public async Task <IActionResult> ProjectEdit(int id, ProjectBindingModel incomingModel) { if (!ModelState.IsValid) { RedirectToAction("Details", "Projects", id); } var model = DbContext.Projects.FirstOrDefault(i => i.Id == id); //model.Image1280X478 = incomingModel.ProjectModel.Image1280X478; //model.Image400X354 = incomingModel.ProjectModel.Image400X354; //model.Image450X398 = incomingModel.ProjectModel.Image450X398; //model.Image550X365 = incomingModel.ProjectModel.Image550X365; model.Images = incomingModel.Images; DbContext.Projects.Update(model); await DbContext.SaveChangesAsync(); return(RedirectToAction("Details", "Projects", new { id })); }
public void CreateOrUpdate(ProjectBindingModel model) { var element = _projectStorage.GetElement(new ProjectBindingModel { Name = model.Name, Clientid = model.Clientid });; if (element != null && element.Id != model.Id) { throw new Exception("Уже есть такой проект"); } if (model.Id.HasValue) { _projectStorage.Update(model); } else { _projectStorage.Insert(model); } }
public void Equals_ProejctBindingModels_ResultExpected(ProjectBindingModel x, ProjectBindingModel y, bool expectedResult) { Assert.Equal(expectedResult, Equals(x, y)); }
public ActionResult NewProject(Guid profileId, ProjectBindingModel form) { var profile = _uow.Profiles.FindById(profileId); profile.AddProject(form.Name, form.Description, form.Role, form.TotalBudget, form.Duration, form.OtherCompany); _uow.Save(); return RedirectToAction<UserProfileController>(c => c.Index()); }
public ActionResult NewProject(Guid profileId) { var vm = new ProjectBindingModel() { ProfileId = profileId }; return View(vm); }
public async Task <IActionResult> SaveAsync([FromForm] ProjectBindingModel model) { Project entity; //var userId = await _identityService.GetUserIdAsync(User.Identity.Name); if (model.IsModified) { entity = await _projectRepository.GetByIdAsync(model.Id); entity.Title = model.Title; entity.Description = model.Description; entity.Languages = model.Languages; entity.Libraries = model.Libraries; entity.Tools = model.Tools; entity.StartedOn = model.StartedOn; entity.Status = model.Status; entity.CompletedOn = model.CompletedOn; //entity.UpdatedBy = userId; entity.UpdatedOn = DateTime.Now; entity.EntityState = EntityState.Modified; foreach (var item in entity.ProjectClients) { item.EntityState = EntityState.Unchanged; } foreach (var item in entity.ProjectImages) { item.EntityState = EntityState.Unchanged; } ProjectClient projectClientEntity; foreach (var item in model.ProjectClients) { projectClientEntity = entity.ProjectClients.FirstOrDefault(x => x.Name == item.Name && x.Email == item.Email && x.Organization == item.Organization); if (projectClientEntity == null) { projectClientEntity = new ProjectClient { Name = item.Name, Email = item.Email, Organization = item.Organization, Description = item.Description }; entity.ProjectClients.Add(projectClientEntity); } else { projectClientEntity.Name = item.Name; projectClientEntity.Email = item.Email; projectClientEntity.Organization = item.Organization; projectClientEntity.Description = item.Description; projectClientEntity.EntityState = EntityState.Modified; } } await _projectRepository.UpdateAsync(entity); } else { entity = _mapper.Map <Project>(model); //entity.AddedBy = userId; var directory = Path.Combine(FileSavePaths.UploadPath, Path.GetRandomFileName()); Directory.CreateDirectory(directory); ProjectImage projectImageEntity; string trustedFileNameForFileStorage; foreach (var item in model.ProjectImages) { trustedFileNameForFileStorage = Path.GetRandomFileName(); projectImageEntity = new ProjectImage { Caption = WebUtility.HtmlEncode(item.Image.FileName), Path = Path.Combine(directory, trustedFileNameForFileStorage), IsPrimary = item.IsPrimary }; var streamedFileContent = await _formFileProcessor.ProcessFormFile <ProjectImageBindingModel>(item.Image, ModelState, PermittedFileExtensions.ImageExtensions); using var targetStream = System.IO.File.Create(projectImageEntity.Path); await targetStream.WriteAsync(streamedFileContent); _logger.LogInformation($"Uploaded file '{projectImageEntity.Caption}' saved to '{projectImageEntity.Path}' as {trustedFileNameForFileStorage}"); entity.ProjectImages.Add(projectImageEntity); } await _projectRepository.AddAsync(entity); } return(Ok()); }