Пример #1
0
        public async Task <IHttpActionResult> PostAsync([FromBody] ProjectItemDto model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            var user = await _userManager.FindByEmailAsync(User.Identity.Name, cancellationToken);

            if (user == null)
            {
                return(NotFound());
            }
            if (model.Sender == null || model.Sender.Address == null)
            {
                model.Sender = MailAddressItem.Create(ApiSecurity.CurrentUserName);
            }

            var project = new ProjectItem {
                Name = model.Name, Sender = model.Sender
            };
            var validationResult = await _projectManager.CreateAsync(project, new[] { user }, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }

            var contact = new ContactItem {
                Email = model.Sender
            };
            var businessTag = new BusinessTagItem {
                Name = "Feliratkozott", Color = "#00ff00"
            };
            await _projectManager.AddContactAsync(project, contact, cancellationToken);

            await _projectManager.AddBusinessTagAsync(project, businessTag, cancellationToken);

            await _projectManager.SetBusinessTagsAsync(new[] { contact.Id }, new[] { businessTag.Id }, new int[0], cancellationToken);

            return(CreatedAtRoute("Projects.GetById", new RouteValueDictionary {
                { "id", project.Id }
            }, new ProjectResultDto
            {
                Id = project.Id,
                Name = project.Name,
                Sender = project.Sender
            }));
        }
        public async Task <IHttpActionResult> PostAsync(int projectId, [FromBody] ContactItemDto model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var project = await _projectManager.FindByIdAsync(projectId, cancellationToken);

            await ApiSecurity.AuthorizeAsync(project, AccessPermission.CanEdit, cancellationToken);

            var sponsor = default(ContactItem);

            if (model.SponsorId != null)
            {
                sponsor = await _projectManager.GetContactByIdAsync((int)model.SponsorId, cancellationToken);
            }
            var contact = new ContactItem
            {
                Sponsor    = sponsor,
                FacebookId = model.FacebookId,
                Email      = model.Email,
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                NickName   = model.NickName,
                Gender     = model.Gender,
                Birthday   = model.Birthday,
                Phones     = model.Phones,
                Comment    = model.Comment
            };
            var validationResult = await _projectManager.AddContactAsync(project, contact, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }
            return(CreatedAtRoute("Project.Contacts.GetById", new RouteValueDictionary {
                { "id", contact.Id }
            }, contact));
        }
Пример #3
0
        public async Task <ActionResult> Create(WorkIssue workIssue)
        {
            if (ModelState.IsValid)
            {
                if (!workIssue.IsValid())
                {
                    if (Request.IsAjaxRequest())
                    {
                        return(PartialView("_NotifyMessage", "Issue is not valid"));
                    }
                    else
                    {
                        return(View("_NotifyMessage", "Issue is not valid"));
                    }
                }
                workIssue.Id        = Guid.NewGuid();
                workIssue.CreatedBy = User.Identity.Name;
                workIssue.PrepareToCreate();
                workIssue.Update();

                if (workIssue.Tags.Count > 0)
                {
                    var projects        = ProjectManager.GetAllOf(User.Identity.Name).ToList();
                    var _tag            = workIssue.Tags[0].ToLower();
                    var _selectProjects = projects
                                          .Where(t => t.Title.ToLower().Contains(_tag))
                                          .ToList();

                    if (_selectProjects != null && _selectProjects.Any())
                    {
                        workIssue.ProjectId = _selectProjects.FirstOrDefault().Id;
                    }
                    else
                    {
                        var _project = ProjectManager.GetByName(_tag);
                        if (_project != null)
                        {
                            workIssue.ProjectId = _project.Id;
                        }
                    }
                }

                IssueManager.Insert(workIssue);

                if (workIssue.ProjectId.HasValue)
                {
                    var _project = ProjectManager.GetById(workIssue.ProjectId.Value);
                    if (!_project.IsOf(User.Identity.Name))
                    {
                        Contact contact = new Contact();
                        contact.CreatedBy = User.Identity.Name;
                        contact.Email     = User.Identity.Name;
                        contact.UserName  = User.Identity.Name;
                        contact.Projects.Add(_project);
                        workIssue.Contacts.Add(contact);
                        await ProjectManager.AddContactAsync(_project.Id, contact);
                    }
                }

                //if(workIssue.HasInnerMembers())
                //{
                //    var _innerMembers = workIssue.GetInnerMembers();
                //    foreach(string _member in _innerMembers)
                //    {
                //        Contact _contact = new Contact();
                //        _contact.Email = _member;
                //        _contact.UserName = _member;
                //        _contact.CreatedBy = User.Identity.Name;
                //        await ContactManager.AddContactAsync(_contact, User.Identity.Name);
                //    }
                //}

                if (Request.IsAjaxRequest())
                {
                    var _viewObject = Mapper.Map <WorkIssue, IssueView>(workIssue);
                    return(PartialView("Issues/_IssueItem", _viewObject));
                }
                return(RedirectToAction("Details", "WorkIssues", new { id = workIssue.Id }));
            }

            return(View(workIssue));
        }