Пример #1
0
        // GET: GroupManage
        public ActionResult Create()
        {
            GroupViewModels viewModel = new GroupViewModels();

            //viewModel.GroupTypeDic = Constants.DIC_GROUP_TYPE;
            return(View(viewModel));
        }
Пример #2
0
        public ActionResult Edit(GroupViewModels pt)
        {
            Group p = ctx.Groups.Find(pt.Id);

            p.Name = pt.Name;
            ctx.SaveChanges();
            return(RedirectToAction("GetAllGroups"));
        }
Пример #3
0
 public ActionResult Add(GroupViewModels pt)
 {
     ctx.Groups.Add(new Group
     {
         Name = pt.Name
     });
     ctx.SaveChanges();
     return(RedirectToAction("GetAllGroups"));
 }
Пример #4
0
        public ActionResult Edit(int id)
        {
            Group           p     = ctx.Groups.Find(id);
            GroupViewModels model = new GroupViewModels()
            {
                Id   = p.Id,
                Name = p.Name
            };

            return(View(model));
        }
Пример #5
0
 public ActionResult AddGroup(GroupViewModels model)
 {
     if (model != null)
     {
         Group group = new Group()
         {
             Name = model.Name
         };
         _context.Groups.Add(group);
         _context.SaveChanges();
     }
     return(RedirectToAction("GetAllGroups"));
 }
Пример #6
0
        public ActionResult Create(GroupViewModels model)
        {
            string token = "";

            if (Session["accessToken"] != null)
            {
                token = (string)Session["accessToken"];
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
            if (ModelState.IsValid)
            {
                string[] stringSeparators = new string[] { "," };
                if (model.Tags != null)
                {
                    string[] tags = model.Tags.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                    model.Members = tags.Count();
                    if (tags.Count() > 0)
                    {
                        model.TagList = new List <string>(tags);
                    }
                }

                // call api add new
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    client.BaseAddress = new Uri("http://localhost:65076/api/Group/");

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <GroupViewModels>("CreateGroup", model);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                    ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
Пример #7
0
        public ActionResult Details(int?groupId)
        {
            string token = "";

            if (Session["accessToken"] != null)
            {
                token = (string)Session["accessToken"];
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
            if (groupId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            GroupViewModels group = null;

            using (var client = new HttpClient())
            {
                //client.BaseAddress = new Uri("http://localhost:65076/api");
                //client.DefaultRequestHeaders.Accept.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                string url_api = "http://localhost:65076/api/Group/" + groupId + "/details";
                //HTTP GET
                var responseTask = client.GetAsync(url_api);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <GroupViewModels>();
                    readTask.Wait();

                    group = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    group = new GroupViewModels();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            return(View(group));
        }
        public IHttpActionResult CreateGroup(GroupViewModels create)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    // add group
                    var group = new t_group()
                    {
                        GroupName   = create.GroupName,
                        GroupType   = create.GroupType,
                        Description = create.Description,
                        Members     = create.Members
                    };
                    db.t_group.Add(group);
                    db.SaveChanges();
                    // add members
                    int groupId = group.GroupId;
                    foreach (var item in create.TagList)
                    {
                        var member = new t_memeber
                        {
                            Name    = item,
                            Email   = item,
                            GroupId = groupId,
                            Status  = "1"
                        };
                        db.t_memeber.Add(member);
                    }
                    db.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(NotFound());
                }
            }

            return(Ok());
        }
 public ActionResult Combine(GroupViewModels model)
 {
     return(View());
 }
Пример #10
0
        public async Task <IActionResult> UpdateGroupName(int groupId, [FromBody] GroupViewModels model)
        {
            Result result = await _groupGateaway.UpdateGroupName(groupId, model.GroupName);

            return(this.CreateResult(result));
        }
Пример #11
0
        public async Task <IActionResult> AddGroup([FromBody] GroupViewModels model)
        {
            Result result = await _groupGateaway.AddGroup(model.OwnerID, model.GroupName);

            return(Ok(result));
        }
Пример #12
0
        private void OnClientGroupCreated(ClientGroupDto obj)
        {
            var groupViewModel = new DefaultClientGroupViewModel(obj, Clients);

            if (Groups.TryAdd(groupViewModel.ClientGroupId, groupViewModel))
            {
                _appDispatcher.Current.BeginInvoke(DispatcherPriority.Background, (Action)(() => GroupViewModels.Add(groupViewModel)));
            }
        }
Пример #13
0
 private void OnClientGroupRemoved(int obj)
 {
     if (Groups.TryRemove(obj, out var groupViewModel))
     {
         _appDispatcher.Current.BeginInvoke(DispatcherPriority.Background, (Action)(() => GroupViewModels.Remove(groupViewModel)));
     }
 }