Exemplo n.º 1
0
        public ActionResult Result(int currentrecord)
        {
            FacilityMaster @facility           = _context.FacilityMasters.Find(currentrecord);
            Organisation   currentOrganisation = @facility.OOrganisation;
            List <int>     participantsIds     = null;

            if (currentrecord != 0)
            {
                List <UserLoginInformation> usersInDb = new List <UserLoginInformation>();

                usersInDb.AddRange(@facility.GetAssocaitedFacilityAdmins());

                participantsIds = usersInDb.Select(x => x.USERID).ToList();
            }
            List <MyNode> nodes = new List <MyNode>();

            MyOrganisation @org = new MyOrganisation();

            @org.Name  = currentOrganisation.Name;
            @org.Value = currentOrganisation.OrganisationId;

            MyNode orgNode = new MyNode
            {
                text      = org.Name,
                value     = org.Value,
                icon      = "glyphicon glyphicon-home",
                backColor = "#ffffff",
                color     = "#428bca",
                //state = new state() { @checked = true, disabled = false, expanded = true, selected = false },
                nodetype = MyNodeType.Organisation
            };

            List <MyFacility> facilities = new List <MyFacility>
            {
                new MyFacility
                {
                    Name = @facility.FacilityMasterName,
                    ParentOrganisationId = @facility.OrganisationId,
                    Value = @facility.FacilityMasterId
                }
            };

            if (facilities.Count > 0)
            {
                orgNode.nodes = new List <MyNode>();
                foreach (MyFacility @fac in facilities)
                {
                    MyNode facNode = new MyNode
                    {
                        parent    = orgNode.value,
                        text      = fac.Name,
                        value     = fac.Value,
                        icon      = "glyphicon glyphicon-th-list",
                        backColor = "#ffffff",
                        color     = "#66512c",
                        //state = new state() { @checked = true, disabled = false, expanded = true, selected = false },
                        nodetype = MyNodeType.Facility
                    };
                    List <MyUser> users = @fac.GetAllMatchingUsers();
                    if (users != null && users.Count > 0)
                    {
                        facNode.nodes = new List <MyNode>();
                        foreach (MyUser @user in users)
                        {
                            MyNode userNode = new MyNode
                            {
                                parent    = facNode.value,
                                text      = user.Name,
                                value     = user.Value,
                                icon      = "glyphicon glyphicon-user",
                                backColor = "#ffffff",
                                color     = "#31708f",
                                nodetype  = MyNodeType.User
                            };
                            if (ChatGroupController.CheckIfMatchingMyUserExists(participantsIds, userNode) != null)
                            {
                                userNode.state = new state
                                {
                                    @checked = true,
                                    disabled = false,
                                    expanded = true,
                                    selected = false
                                };
                            }
                            facNode.nodes.Add(userNode);
                        }
                    }
                    orgNode.nodes.Add(facNode);
                }
            }
            nodes.Add(orgNode);
            return(Json(nodes, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public string UpdateFacilittMaster(FacilityMaster facilityinfo)
        {
            try
            {
                UserLoginInformation loggedinUser = (UserLoginInformation)LoginController.ActiveUser;
                if (facilityinfo.FacilityMasterId == 0)
                {
                    facilityinfo.CreatedById  = loggedinUser.USERID.ToString();
                    facilityinfo.ModifiedById = loggedinUser.USERID.ToString();
                    facilityinfo.CreatedDate  = DateTime.Now;
                    facilityinfo.ModifiedDate = DateTime.Now;
                    _context.FacilityMasters.Add(facilityinfo);
                    _context.SaveChanges();
                }
                else
                {
                    try
                    {
                        using (TransactionScope transactionScope = new TransactionScope())
                        {
                            try
                            {
                                using (kryptoEntities1 db = new kryptoEntities1())
                                {
                                    facilityinfo = Updateobject(facilityinfo.FacilityMasterId, facilityinfo);
                                    facilityinfo.ModifiedById    = loggedinUser.USERID.ToString();
                                    facilityinfo.ModifiedDate    = DateTime.Now;
                                    db.Entry(facilityinfo).State = EntityState.Modified;
                                    db.SaveChanges();

                                    List <MyNode> responseNodes =
                                        JsonConvert.DeserializeObject <List <MyNode> >(facilityinfo.UserSelections);
                                    List <UserLoginInformation> usersInDb = new List <UserLoginInformation>();

                                    usersInDb.AddRange(facilityinfo.GetAssocaitedFacilityAdmins());

                                    List <int> indb         = usersInDb.Select(x => x.USERID).ToList();
                                    List <int> inselections = responseNodes.Select(x => x.value).ToList();

                                    var toInclude = UserDatatablesController.ExcludedRight(indb, inselections);
                                    var toExclude = UserDatatablesController.ExcludedLeft(indb, inselections);

                                    foreach (int @in in toInclude)
                                    {
                                        UserLoginInformation current = db.UserLoginInformations.Find(@in);
                                        current.IsFacilityAdmin = true;
                                        db.Entry(current).State = EntityState.Modified;
                                    }
                                    foreach (int @out in toExclude)
                                    {
                                        UserLoginInformation current = db.UserLoginInformations.Find(@out);
                                        current.IsFacilityAdmin = false;
                                        db.Entry(current).State = EntityState.Modified;
                                    }
                                    db.SaveChanges();
                                }
                                transactionScope.Complete();
                            }
                            catch (Exception ee)
                            {
                                return("FAIL");
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        return("FAIL");
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                return("FAIL");
            }
            return("SUCESS");
        }