/// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        public Role CreateRole(string roleName)
        {
            Role r = new Role(roleName);

            _repo.Add(r);
            return(r);
        }
 /// <summary>
 /// Adds the command log.
 /// </summary>
 /// <param name="log">The log.</param>
 public void AddCommandLog(CommandLog log)
 {
     _repo.Add(log);
     //Add new log
     _context.CommandLogs.Add(log);
     _context.SaveChanges();
 }
Beispiel #3
0
        public ActionResult Create(App model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("", "App name cannot be empty");
                return(View());
            }
            if (string.IsNullOrEmpty(model.Logo))
            {
                ModelState.AddModelError("", "Logo cannot be empty");
                return(View());
            }
            if (string.IsNullOrEmpty(model.Url))
            {
                ModelState.AddModelError("", "Url cannot be empty");
                return(View());
            }
            if (string.IsNullOrEmpty(model.Author))
            {
                ModelState.AddModelError("", "Author cannot be empty");
                return(View());
            }
            try
            {
                // TODO: Add insert logic here
                _applicationRepository.Add(model);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Application(Application application, string userName)
        {
            ApplicationRepository appRep  = new ApplicationRepository(Properties.Settings.Default.ConStr);
            UserRepository        userRep = new UserRepository(Properties.Settings.Default.ConStr);

            application.UserId = userRep.GetByUserName(User.Identity.Name).Id;
            appRep.Add(application);
            return(Redirect("/home/home"));
        }
        public ActionResult AddApplication(Application App)
        {
            Application          updaterecircument = null;
            HumanResourceContext context           = new HumanResourceContext();

            if (App.AppId == 0)
            {
                updaterecircument = apprepo.Add(App);
            }
            else
            {
                updaterecircument = apprepo.Update(App);
            }
            return(RedirectToAction("Application", "HumanResource"));
        }
        public void CreateApplication(Domain.Context.Application application)
        {
            if (application == null)
                throw new ArgumentNullException("application");

            using (UserRepository userRepository = new UserRepository())
            {
                var user = userRepository.Get(application.UserId);

                if (user != null)
                {
                    var achievement = user.Achievements.SingleOrDefault<Achievement>(a => a.Year == DateTime.Now.Year);
                    if (achievement != null)
                    {
                        //using (SpecialityEnrollPlanRepository enrollPlanRepository = new SpecialityEnrollPlanRepository())
                        //{
                        //    var enrollPlans = enrollPlanRepository.GetFiltered(e => e.SpecialityId == application.SpecialityId && e.Province == achievement.Province).SingleOrDefault<SpecialityEnrollPlan>();
                        //    if (enrollPlans != null)
                        //    {
                        using (ApplicationRepository appRepository = new ApplicationRepository())
                        {
                            var apps = appRepository.GetFiltered(app => app.Year == application.Year && app.Batch == application.Batch && app.ApplicationSequence == application.ApplicationSequence);
                            if (apps != null && apps.ToList<Domain.Context.Application>().Count > 0)
                            {
                                // throw existing application exception
                                throw new UniversityApplicationExistException(Resource.UserMessages.ex_UniversityApplicationExist);
                            }
                            appRepository.Add(application);
                            appRepository.Commit();
                        }
                        //}
                        //else
                        //{
                        //    // throw no enroll plan exception
                        //    throw new UniversityNoEnrollPlanException(Resource.ResourceMessage.ex_UnversityNoEnrollPlan);
                        //}
                        //}
                    }
                    else
                    {
                        throw new UniversityApplicationExistException(Resource.UserMessages.ex_AchievementNotExist);
                    }
                }
            }
        }
        public void Post([FromBody] string json)
        {
            Application app = JsonConvert.DeserializeObject <Application>(json);

            _rep.Add(app);
        }
 /// <summary>
 /// Creates the user.
 /// </summary>
 /// <param name="u">The user to create</param>
 /// <returns>The Newly Created User</returns>
 public User CreateUser(User u)
 {
     _repo.Add(u);
     return(GetUser(u.UserId));
 }
        public void CreateApplication(Domain.Context.Application application)
        {
            if (application == null)
                throw new ArgumentNullException("application");

            AccountRepository accountRepository = new AccountRepository();
            var account = accountRepository.Get(application.UserId);

            if (account != null)
            {
                var achievement = account.Achievements.ToList<Achievement>().SingleOrDefault<Achievement>( a=> a.Year.Year == DateTime.Now.Year);
                if (achievement != null)
                {
                    EnrollPlanRepository enrollPlanRepository = new EnrollPlanRepository();
                    var enrollPlans = enrollPlanRepository.GetFiltered(e => e.SpecialityId == application.SpecialityId && e.Province == achievement.Province).SingleOrDefault<EnrollPlan>();
                    if (enrollPlans != null)
                    {
                        ApplicationRepository appRepository = new ApplicationRepository();

                        var apps = appRepository.GetFiltered(app => app.Year.Year == application.Year.Year && app.Batch == application.Batch && app.ApplicationSequence == application.ApplicationSequence);
                        if (apps != null && apps.ToList<Domain.Context.Application>().Count > 0)
                        {
                            // TODO: throw existing application exception
                        }

                        appRepository.Add(application);
                        appRepository.Commit();
                    }
                    else
                    {
                        // TODO: throw no enroll plan exception
                    }
                }
            }
        }
Beispiel #10
0
        public IActionResult Create(string email, IFormFile file)
        {
            // List of messages to return to the client
            var messages = new List <Message>();

            #region application descriptor validations

            // File with JSON application descriptor is required
            if (file == null)
            {
                messages.Add(new Message(MessageTypeEnum.Error,
                                         0001,
                                         new List <string>()));
                return(BadRequest(messages));
            }

            // Get JObject from input file
            JObject applicationDescriptorJObject;
            using (var reader = new StreamReader(file.OpenReadStream()))
            {
                // Try to parse file to JObject - only valid JSON files are parsed
                try
                {
                    applicationDescriptorJObject = JObject.Parse(reader.ReadToEnd());
                }
                // If parsing was unsuccessfull, return error message containing location of error
                catch (JsonReaderException e)
                {
                    messages.Add(new Message(MessageTypeEnum.Error,
                                             0002,
                                             new List <string>()
                    {
                        e.Message
                    }));
                    return(BadRequest(messages));
                }
            }
            var sharedAppInitHelper = new SharedAppInitHelper();

            // With successfully parsed JSON file, validate it against schema
            var schemaValidationMessages = sharedAppInitHelper.ValidateJSONAgainstSchema(applicationDescriptorJObject);
            // If validation JSON is not valid return errors
            if (schemaValidationMessages.Count != 0)
            {
                return(BadRequest(schemaValidationMessages));
            }
            // Get ApplicationDescriptor class instance from JObject
            var applicationDescriptor = applicationDescriptorJObject.ToObject <ApplicationDescriptor>();

            // LoginApplicationName must be unique
            var applicationRepository = new ApplicationRepository(context);
            var applicationModel      = applicationRepository.GetByLoginApplicationName(applicationDescriptor.LoginApplicationName);
            if (applicationModel != null)
            {
                messages.Add(new Message(MessageTypeEnum.Error,
                                         0003,
                                         new List <string>()
                {
                    applicationDescriptor.LoginApplicationName
                }));
            }
            // Validate datasets and attributes
            messages.AddRange(sharedAppInitHelper.ValidateDescriptor(applicationDescriptor));

            if (messages.Count != 0)
            {
                return(BadRequest(messages));
            }

            #endregion

            // Set default values to the application descriptor
            sharedAppInitHelper.SetDefaultDescriptorValues(applicationDescriptor);

            #region create new application

            using (var transaction = context.Database.BeginTransaction())
            {
                // Create new application and add it to the database
                var serializedApplicationDescriptor = JsonConvert.SerializeObject(applicationDescriptor);
                var newApplication = new ApplicationModel {
                    LoginApplicationName      = applicationDescriptor.LoginApplicationName,
                    ApplicationDescriptorJSON = serializedApplicationDescriptor
                };
                applicationRepository.Add(newApplication);

                // Create new admin account for the application
                // Random password
                string newPassword;
                var    minPasswordLength = applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.PasswordAttribute.Min;
                if (minPasswordLength != null)
                {
                    newPassword = PasswordHelper.GenerateRandomPassword((int)minPasswordLength);
                }
                else
                {
                    newPassword = PasswordHelper.GenerateRandomPassword(Constants.MinSaferPasswordLength);
                }
                // Admin rights
                var appInitHelper    = new AppInitHelper();
                var newRights        = appInitHelper.GetAdminRights(newApplication, applicationDescriptor);
                var rightsRepository = new RightsRepository(context);
                rightsRepository.Add(newRights);
                var salt    = PasswordHelper.GetSalt();
                var newUser = new UserModel
                {
                    Application  = newApplication,
                    PasswordHash = PasswordHelper.ComputeHash(salt + newPassword),
                    PasswordSalt = salt,
                    Data         = appInitHelper.GetDefaultAdminDataDictionary(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor),
                    Rights       = newRights,
                    Language     = applicationDescriptor.DefaultLanguage
                };
                var userRepository = new UserRepository(context);
                userRepository.Add(newUser);

                // Try to send login details to admin account to email from parametres
                try
                {
                    appInitHelper.SendEmailWithCredentials(email, applicationDescriptor.ApplicationName, newApplication.LoginApplicationName, newPassword);
                }
                catch
                {
                    messages.Add(new Message(MessageTypeEnum.Error,
                                             0025,
                                             new List <string>()
                    {
                        email
                    }));
                    return(BadRequest(messages));
                }

                // Commit all
                transaction.Commit();
            }
            // If everythong was ok, save changes to the database
            context.SaveChangesAsync();

            #endregion

            messages.Add(new Message(MessageTypeEnum.Info,
                                     0026,
                                     new List <string>()
            {
                applicationDescriptor.ApplicationName, email
            }));
            return(Ok(messages));
        }