Exemple #1
0
        public string PostSpace(string value)
        {
            JObject obj = JObject.Parse(value);

            var Id            = obj["Id"];
            var Name          = obj["Name"];
            var Configuration = obj["Configuration"];

            if (Id != null && !string.IsNullOrEmpty(Id.ToString()))
            {
                var space = db.Spaces.Find(Id.ToString());
                if (space == null)
                {
                    logger.Info("NoSpaceFoundInDb - User : "******"NoSpaceFoundInDb" }));
                }

                DesignManager designManager = new DesignManager();
                // Create css file specific for this space with the colour provided by the user async
                designManager.CreateUpdateCssFileForSpace(space.Id, designManager.getColourDesignOfSpace(Configuration.ToString()));

                space.Name          = Name.ToString();
                space.Configuration = Configuration.ToString();
                space.Metadata      = ActivityFactory.SetMetadata(User.Identity.GetUserName(), value, "PostSpace", space.Metadata);

                db.Entry(space).State = EntityState.Modified;
                db.SaveChanges();

                return(JsonConvert.SerializeObject(new { error = false, space = space }));
            }
            else
            {
                var space = new Space();
                space.Name          = Name.ToString();
                space.Configuration = Configuration.ToString();
                space.Metadata      = ActivityFactory.SetMetadata(User.Identity.GetUserName(), value, "PostSpace", space.Metadata);

                db.Spaces.Add(space);
                db.SaveChanges();
                return(JsonConvert.SerializeObject(new { error = false, space = space }));
            }
        }
 public string PostRestore(string value)
 {
     try
     {
         var entities = JsonConvert.DeserializeObject <List <Entity> >(value);
         foreach (var entity in entities)
         {
             var entityModified = EntityService.findEntity(entity);
             entityModified                 = EntityService.OnRestoreEntity(entityModified);
             entityModified.Metadata        = ActivityFactory.SetMetadata(User.Identity.GetUserName(), value, "PostRestore", entityModified.Metadata);
             db.Entry(entityModified).State = EntityState.Modified;
         }
         db.SaveChanges();
         return(JsonConvert.SerializeObject(new { error = false, notification = "trashItemsRestoreSuccess" }));
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         return(JsonConvert.SerializeObject(new { error = true, notification = "trashItemsRestoreError" }));
     }
 }
Exemple #3
0
        public string PostSpaceForCurrentUser(string value)
        {
            JObject obj = JObject.Parse(value);

            var Name          = obj["Name"];
            var Configuration = obj["Configuration"];

            ApplicationDbContext         context     = new ApplicationDbContext();
            IUserStore <ApplicationUser> store       = new UserStore <ApplicationUser>(context);
            ApplicationUserManager       UserManager = new ApplicationUserManager(store);
            var claims = UserManager.GetClaims(User.Identity.GetUserId());
            var claim  = claims.Where(a => a.Type == "SpaceId").FirstOrDefault();

            if (claim != null)
            {
                var space = db.Spaces.Find(claim.Value);
                if (space == null)
                {
                    logger.Info("NoSpaceFoundInDb - User : "******"NoSpaceFoundInDb" }));
                }

                DesignManager designManager = new DesignManager();
                // Create css file specific for this space with the colour provided by the user async
                designManager.CreateUpdateCssFileForSpace(space.Id, designManager.getColourDesignOfSpace(Configuration.ToString()));

                space.Name          = Name.ToString();
                space.Configuration = Configuration.ToString();
                space.Metadata      = ActivityFactory.SetMetadata(User.Identity.GetUserName(), value, "PostSpaceForCurrentUser", space.Metadata);

                db.Entry(space).State = EntityState.Modified;
                db.SaveChanges();

                return(JsonConvert.SerializeObject(new { error = false, space = space }));
            }

            logger.Info("NoSpaceFoundInUserConfig - User : "******"NoSpaceFoundInUserConfig" }));
        }
Exemple #4
0
 public string PostDeleteMultiBuilding(string value)
 {
     try
     {
         ActivityFactory.SetActivityAsync(User.Identity.GetUserId());
         var buildingids = JsonConvert.DeserializeObject <List <string> >(value);
         foreach (var id in buildingids)
         {
             var building = db.Buildings.Find(id);
             if (building != null)
             {
                 EntityService.OnDeleteEntity(building, User.Identity.GetUserId());
                 building.Metadata = ActivityFactory.SetMetadata(User.Identity.GetUserName(), value, "PostDeleteMultiBuilding", building.Metadata);
             }
         }
         db.SaveChanges();
         return(JsonConvert.SerializeObject(new { error = false, notification = "DeleteMultiNotifSuccess", response = "" }));
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         return(JsonConvert.SerializeObject(new { error = true, notification = "ServerError" }));
     }
 }