Esempio n. 1
0
        public async Task <GroupViewModel> Add(string name)
        {
            var g = _db.Groups.Create();

            g.Name = name;
            g.ApplicationInstance = new ApplicationInstance {
                Id = _appInfo.InstanceId
            };

            var changes = await _db.SaveChangesAsync();

            var vm = Mapper.Map <Group, GroupViewModel>(g);

            return(vm);
        }
Esempio n. 2
0
        public async Task <RoleViewModel> Add(int appId, string name, string description, int modifiedBy)
        {
            var app = await _ctx.Applications.FindAsync(appId);

            if (app == null)
            {
                return(null);
            }
            var role = new Role
            {
                Name        = name,
                Description = description,
                Application = app,
                ModifiedBy  = modifiedBy
            };

            _ctx.Roles.Add(role);
            await _ctx.SaveChangesAsync();

            var roleVm = Mapper.Map <Role, RoleViewModel>(role);

            return(roleVm);
        }
Esempio n. 3
0
        public async Task <int> UpdateProfile(Person ProfileFromBanner)
        {
            string username = ProfileFromBanner.Email.Substring(0, ProfileFromBanner.Email.IndexOf('@'));

            var appCentralUser = _ctx.Users.FirstOrDefault(x => x.UserName == username);

            var cache = _ctx.Profiles.FirstOrDefault(x => x.UserId == appCentralUser.Id);

            cache.LastLoggedIn  = DateTime.Now;
            cache.FirstName     = ProfileFromBanner.Name;
            cache.Email         = ProfileFromBanner.Email;
            cache.LastName      = ProfileFromBanner.LastName;
            cache.MiddleInitial = ProfileFromBanner.MiddleInitial;
            cache.PhoneNumber   = ProfileFromBanner.PhoneNumber;
            cache.UserId        = appCentralUser.Id;

            return(await _ctx.SaveChangesAsync());
        }
Esempio n. 4
0
        public async Task <FileViewModel> HandleFileUpload(string originalFileName, FileInfo uploadedFileInfo, int instanceId, int userId)
        {
            var instance = await _db.ApplicationInstances.FindAsync(instanceId);

            if (instance == null)
            {
                return(null);
            }
            if (uploadedFileInfo.Length <= 0)
            {
                return(null);
            }
            var guid    = Guid.NewGuid();
            var fileExt = Path.GetExtension(originalFileName);

            var serverName = guid + fileExt;

            var fileDb = new UploadedFile
            {
                Name                = originalFileName,
                ServerName          = serverName,
                Size                = (int)uploadedFileInfo.Length,
                ApplicationInstance = instance,
                DateCreated         = DateTime.Now,
                DateModified        = DateTime.Now,
                CreatedBy           = userId,
                ModifiedBy          = userId,
                IsDeleted           = false,
                Pending             = true
            };

            _db.Files.Add(fileDb);
            await _db.SaveChangesAsync();

            //save to disk
            var filePath = Path.Combine(string.Format("{0}{1}\\{2}", _path, instanceId, serverName));

            uploadedFileInfo.MoveTo(filePath);
            //return new id

            var vm = Mapper.Map <UploadedFile, FileViewModel>(fileDb);

            return(vm);
        }