Exemplo n.º 1
0
        public void GetAll_ShouldReturnNotEmptyList_WhenDataExists()
        {
            _groupService.Add("Group 1");

            var groups = _groupService.GetAll().ToList();

            groups.Count().Should().BeGreaterThan(0);
        }
Exemplo n.º 2
0
        public IHttpActionResult Post([FromBody] GroupDto form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var group = Mapper.Map <GroupDto, Group>(form);

                    _groupService.Add(group);

                    var groupDto = GetGroupDto(group);

                    return(Created(new Uri(groupDto.Url), groupDto));
                }
                catch (ArgumentNullException ane)
                {
                    ModelState.AddModelError("", ane.Message);
                }
                catch (PreexistingEntityException pe)
                {
                    ModelState.AddModelError("", pe.Message);
                }
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 3
0
        public ActionResult CreateOrUpdate(FormCollection group)
        {
            if (ModelState.IsValid)
            {
                string groupName = group["GroupName"];
                int    groupId   = int.Parse(group["GroupId"]);
                Group  gr        = _groupService.GetById(groupId);
                if (groupId == 0)
                {
                    _groupService.Add(new Group
                    {
                        GroupName = groupName
                    });
                    TempData["Status"] = "Thêm thành công!";
                }
                else
                {
                    gr.GroupName = groupName;
                    _groupService.Update(gr);
                    TempData["Status"] = "Sửa thành công!";
                }
                return(RedirectToAction("Index"));
            }

            return(View(group));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Add()
        {
            //var currentGroup = _groupService
            //    .All().Where(item => item.ID == Guid.Parse("bddfd36e-9298-4d7c-9c72-f45a857bd465")).Include(item => item.GroupUsers)
            //    .First();
            //currentGroup.Title = "admin 23";
            //currentGroup.IsDefault = false;
            //currentGroup.IsDeleted = false;



            Group currentGroup = new Group()
            {
                Title      = "Administrators 2",
                GroupUsers = _userService.All().Select(item => new GroupUser()
                {
                    UserID = item.ID
                }).ToList(),
            };
            await _groupService.Add(currentGroup);

            //await _userService.Add(newUser);
            await _groupService.Update(currentGroup);

            await _groupService.Delete(currentGroup);

            return(Json(currentGroup));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ID,Name,SelectedItems")] GroupDto group)
        {
            if (ModelState.IsValid)
            {
                if (group.SelectedItems != null &&
                    group.SelectedItems.Length > 0)
                {
                    group.Suppliers = new List <SupplierDto>();

                    /* Split SelectedSuppliers by ';' */
                    string[] supplierStrs = group.SelectedItems.Split(';');

                    /* Iterate through groupStrs, add selected groups into supplierDb and remeber tested groups */
                    foreach (string supplierStr in supplierStrs)
                    {
                        try
                        {
                            int id = Int32.Parse(supplierStr.Replace("Supplier_", ""));
                            group.Suppliers.Add(SupplierService.GetById(id));
                        }
                        catch (FormatException)
                        {
                            ;
                        }
                    }
                }

                GroupService.Add(group);

                return(RedirectToAction("Index"));
            }

            return(View(group));
        }
 public ActionResult Add(Group group, string Course)
 {
     //if (ModelState.IsValid)
     //{
     groupService.Add(group, Course);
     return(View());
     //}
     //return View(group);
 }
 public ActionResult Create(GroupCreateModel group)
 {
     if (ModelState.IsValid)
     {
         _groupService.Add(group, User.Identity.GetUserId());
         return(RedirectToAction("Index"));
     }
     return(View(group));
 }
        public IActionResult Post([FromBody] GroupDto groupDto)
        {
            Group group = _mapper.Map<Group>(groupDto);

            _groupService.Add(group);

            groupDto = _mapper.Map<GroupDto>(group);

            return Ok(groupDto);
        }
Exemplo n.º 9
0
        public IHttpActionResult Add([FromBody] Group group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _groupService.Add(group);

            return(Ok());
        }
Exemplo n.º 10
0
 public IHttpActionResult SaveGroup(Group group)
 {
     if (string.IsNullOrEmpty(group.Id))
     {
         return(Ok(_service.Add(group)));
     }
     else
     {
         return(Ok(_service.UpdateGroup(group)));
     }
 }
Exemplo n.º 11
0
        public IActionResult Add(Group group)
        {
            var result = _groupService.Add(group);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
        public IActionResult Add(GroupDTO groupDto)
        {
            _mapper = GroupMapping.GetMapper().CreateMapper();
            Group group  = _mapper.Map <GroupDTO, Group>(groupDto);
            var   result = _service.Add(group);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Success.ToString() + " and  " + result.Message));
        }
Exemplo n.º 13
0
        public IHttpActionResult Post(GroupModel newGroup)
        {
            if (newGroup == null)
            {
                throw new ArgumentNullException("Parameter could not be null", "newGroup");
            }

            if (!_groupService.ContainsGroupName(newGroup))
            {
                var groupToAdd = _groupMapper.Map(newGroup);
                _groupService.Add(groupToAdd);
                return(Ok());
            }
            return(BadRequest(string.Format("Group {0} already exist!", newGroup.Name)));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Add(GroupAddDto newGroup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var group = await _groupService.Add(_mapper.Map <Group>(newGroup));

            if (group == null)
            {
                return(BadRequest());
            }

            return(Ok(_mapper.Map <GroupResultDto>(group)));
        }
Exemplo n.º 15
0
 public IHttpActionResult Post(GroupModel newGroup)
 {
     if (newGroup == null)
     {
         throw new ArgumentNullException("Parameter could not be null", "newGroup");
     }
     if (!_groupService.CheckIfGroupNameExists(newGroup))
     {
         if (_groupService.Add(newGroup))
         {
             return(Ok());
         }
     }
     return(BadRequest(string.Format("Group {0} already exist!", newGroup.Name)));
 }
Exemplo n.º 16
0
        public IActionResult Add([FromBody] AddGroupRequest addGroup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result result = _groupService.Add(addGroup);

            if (result.Failure)
            {
                ModelState.AddErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            return(Ok(new EmptyResult()));
        }
Exemplo n.º 17
0
        public HttpResponseMessage Create(HttpRequestMessage request, GroupViewModel groupVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    try
                    {
                        var groupDb = new Group();
                        groupDb.UpdateGroup(groupVm);

                        if (!String.IsNullOrEmpty(groupVm.Image))
                        {
                            var image = ConvertData.Base64ToImage(groupVm.Image);

                            groupDb.Image = groupDb.ID + "_" + groupDb.Name + ".jpg";

                            string filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/fileman/Uploads/")
                                                           + CommonConstants.PathProductCategory + "/" + groupDb.Image);

                            image.Save(filePath, ImageFormat.Jpeg);
                        }

                        _groupService.Add(groupDb);
                        _groupService.Save();

                        var responseData = Mapper.Map <Group, GroupViewModel>(groupDb);
                        response = request.CreateResponse(HttpStatusCode.OK, responseData);
                    }
                    catch (Exception ex)
                    {
                        response = request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                    }
                }
                return response;
            }));
        }
Exemplo n.º 18
0
        public IActionResult Post([FromBody] GroupCreationDto groupCreationDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var group = _mapper.Map <Group>(groupCreationDto);

            if (!_groupService.Add(group))
            {
                return(BadRequest("Group already exists"));
            }

            var createdGroup = _mapper.Map <Group>(group);

            _groupService.Save();

            return(CreatedAtRoute("GetGroup", new { createdGroup.Id }));
        }
Exemplo n.º 19
0
        public async Task <HttpResponseMessage> Create(HttpRequestMessage request, GroupCreateUpdateModel groupVM)
        {
            if (ModelState.IsValid)
            {
                var newGroup = new Group();
                GroupCreateUpdateModel responseData = new GroupCreateUpdateModel();
                newGroup.UpdateGroup(groupVM);
                if (_groupService.IsDuplicateGroup(groupVM.Name, groupVM.ID))
                {
                    return(request.CreateResponse(HttpStatusCode.BadRequest, Common.Constants.MessageSystem.GroupExist));
                }
                else
                {
                    if (_groupService.Add(newGroup) != null)
                    {
                        _groupService.SaveChange();
                        var groupId = _groupService.GetGroupByName(groupVM.Name).ID;
                        var appUser = await AppUserManager.FindByIdAsync(groupVM.GroupLeadID);

                        appUser.GroupId = groupId;
                        var result = await AppUserManager.UpdateAsync(appUser);

                        if (result.Succeeded)
                        {
                            return(request.CreateResponse(HttpStatusCode.Created, responseData));
                        }
                        else
                        {
                            _groupService.Delete(groupId);
                            return(request.CreateResponse(HttpStatusCode.BadRequest, responseData));
                        }
                    }
                    responseData = Mapper.Map <Group, GroupCreateUpdateModel>(newGroup);
                    return(request.CreateResponse(HttpStatusCode.BadRequest, responseData));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Exemplo n.º 20
0
 public JsonResult SaveGroup(string data)
 {
     try
     {
         var model = Newtonsoft.Json.JsonConvert.DeserializeObject <Group>(data);
         if (model.GroupId > 0)
         {
             var group = _groupService.GetGroupById(model.GroupId);
             group.FrontImage  = model.FrontImage;
             group.GroupName   = model.GroupName;
             group.Description = model.Description;
             _groupService.Update(group);
         }
         else
         {
             model.TenantId   = CurrentTenant.TenantId;
             model.Creater    = CurrentUser.UserId;
             model.CreateTime = DateTime.Now;
             model.IsDelete   = 0;
             _groupService.Add(model);
             #region 积分
             IntegrationManager.Instence.FireIntegrationEvent(IntegrationEvents.CreateGroup, CurrentUser.UserId,
                                                              CurrentTenant.TenantId);
             #endregion
         }
         return(Json(new
         {
             result = 1,
             content = LanguageResources.Common.SaveSuccess
         }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new
         {
             result = 0,
             content = LanguageResources.Common.SaveFailed
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 21
0
        public IActionResult Create(GroupDto group)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                _groupService.Add(group);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                if (e is ArgumentNullException || e is ArgumentException)
                {
                    ViewBag.Info = e.Message;
                    return(View());
                }

                return(View("Error"));
            }
        }
Exemplo n.º 22
0
        public ActionResult Create(GroupCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = groupService.Add(new GroupModel
                {
                    Name        = model.Name,
                    Description = model.Description
                }, CurrentUserId);

                if (result)
                {
                    return(RedirectToAction("Index", "Group"));
                }
                else
                {
                    ModelState.AddModelError("", "Group creation failed");
                }
            }

            return(View(model));
        }
        public ActionResult Add(string teamName, int city, string description)
        {
            if (string.IsNullOrEmpty(teamName))
            {
                return(Content("error, invalid Name!"));
            }
            Group group = new Group()
            {
                CityId = city,
                Name   = teamName,
            };

            if (string.IsNullOrEmpty(description))
            {
                group.Description = "";
            }
            else
            {
                group.Description = description;
            }
            GroupService.Add(group);
            return(Content("ok"));
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Create([FromBody] GroupModel model)
        {
            await _service.Add(model);

            return(Ok());
        }
Exemplo n.º 25
0
        public void Add_AddGroups_Verify_MethodCalled()
        {
            //Arrange
            List <Lesson> lessons = new List <Lesson>()
            {
                new Lesson
                {
                    WeekNumber   = Week.FirstWeek,
                    DayOfTheWeek = Day.Thursday,
                    LessonNumber = 1,
                    LessonName   = "Programming",
                    Group        = null,
                    Teacher      = null
                },
                new Lesson
                {
                    WeekNumber   = Week.SecondWeek,
                    DayOfTheWeek = Day.Monday,
                    LessonNumber = 3,
                    LessonName   = "Math",
                    Group        = null,
                    Teacher      = null
                },
                new Lesson
                {
                    WeekNumber   = Week.FirstWeek,
                    DayOfTheWeek = Day.Tuesday,
                    LessonNumber = 3,
                    LessonName   = "Philosophy",
                    Group        = null,
                    Teacher      = null
                }
            };

            Group[] groups =
            {
                new Group
                {
                    CourseNumber = 1,
                    GroupNumber  = 19,
                    Lessons      = lessons
                },
                new Group
                {
                    CourseNumber = 2,
                    GroupNumber  = 16,
                    Lessons      = lessons
                },
                new Group
                {
                    CourseNumber = 3,
                    GroupNumber  = 21,
                    Lessons      = lessons
                },
            };
            Mock <IGroupService> service = new Mock <IGroupService>();

            service.Setup(mock => mock.Add(groups[0])).Verifiable();
            service.Setup(mock => mock.Add(groups[1])).Verifiable();
            service.Setup(mock => mock.Add(groups[2])).Verifiable();

            //Act
            IGroupService Service = service.Object;

            Service.Add(groups[0]);
            Service.Add(groups[1]);
            Service.Add(groups[2]);

            //Assert
            service.VerifyAll();
        }
Exemplo n.º 26
0
 public Task <IResultModel> Add(GroupAddModel model)
 {
     return(_service.Add(model));
 }
        public async Task <IActionResult> Register(Group group)
        {
            var groupAdded = await service.Add(group);

            return(StatusCode(201));
        }
 public IHttpActionResult Add([FromBody] Group group, string Course)
 {
     groupService.Add(group, Course);
     return(Ok());
 }
Exemplo n.º 29
0
 // POST: api/Group
 public IHttpActionResult Post([FromBody] Group value)
 {
     _groupService.Add(value);
     return(Ok(value));
 }
Exemplo n.º 30
0
        public void Seed()
        {
            _userService.Add(new Core.Entities.User()
            {
                Login    = $"AndrewThe",
                Password = "******",
                Email    = "*****@*****.**",
                Roles    = new List <Role> {
                    Role.Admin
                },
                UserName    = "******",
                GroupId     = "29627000-e32d-11e7-b070-a7a2334df747",
                PhoneNumber = "123-123-123"
            });
            var lecturer = new User()
            {
                Id       = Guid.NewGuid().ToString(),
                Login    = $"Lecturer",
                Password = "******",
                Email    = "*****@*****.**",
                Roles    = new List <Role> {
                    Role.Lecturer
                },
                UserName    = "******",
                GroupId     = "29627000-e32d-11e7-b070-a7a2334df747",
                PhoneNumber = "123-123-123"
            };

            _userService.Add(lecturer);

            var cathedra = new Cathedra
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "App Math"
            };

            c.Add(cathedra);
            var group = new Group()
            {
                Id         = Guid.NewGuid().ToString(),
                CathedraId = cathedra.Id,
                Name       = "PMP-51",
                DisciplineConfiguration = new List <DisciplineConfiguration>
                {
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 1
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Socio, RequiredAmount = 1, Semester = 2
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 1
                    },
                    new DisciplineConfiguration {
                        DisciplineType = DisciplineType.Special, RequiredAmount = 1, Semester = 2
                    },
                },
                Course = 5,
            };

            g.Add(group);

            for (int i = 0; i < 99; i++)
            {
                _userService.Add(new User()
                {
                    Login    = $"student{i}",
                    Password = "******",
                    Email    = $"*****@*****.**",
                    Roles    = new List <Role> {
                        Role.Student
                    },
                    UserName    = $"student{i}",
                    Course      = 5,
                    GroupId     = group.Id,
                    PhoneNumber = "123-123-123",
                });

                d.Add(new Discipline
                {
                    Id                 = Guid.NewGuid().ToString(),
                    DisciplineType     = i % 2 == 0 ? DisciplineType.Socio : DisciplineType.Special,
                    IsAvailable        = true,
                    LecturerId         = lecturer.Id,
                    Name               = $"Discipline{i}_11",
                    Semester           = 11,
                    ProviderCathedraId = cathedra.Id
                });
                var di = new Discipline
                {
                    Id                 = Guid.NewGuid().ToString(),
                    DisciplineType     = i % 2 == 0 ? DisciplineType.Socio : DisciplineType.Special,
                    IsAvailable        = true,
                    LecturerId         = lecturer.Id,
                    Name               = $"Discipline{i}_12",
                    Semester           = 12,
                    ProviderCathedraId = cathedra.Id
                };
                d.Add(di);
            }
            var disciplines = d.Find(SearchFilter <Discipline> .FilterByEntity(new Discipline {
                DisciplineType = DisciplineType.Special
            }));

            disciplines = new List <Discipline> {
                disciplines[0], disciplines[1]
            };
            group.DisciplineSubscriptions = disciplines.Select(d => d.Id).ToList();

            g.Update(group.Id, group);
        }