예제 #1
0
        public Entities.User GetUsers(ApiContext apiContext, int id)
        {
            Entities.User user = new Entities.User();

            CoreManagers.UserManager.Get(apiContext, id, out user);

            return(user);
        }
예제 #2
0
        public void InsertUser()
        {
            ReceiptManagement.Common.Entities.User user = new ReceiptManagement.Common.Entities.User();

            user.FirstName = "Faisal";
            user.LastName  = "Nasir";
            user.Password  = "******";
            user.Email     = "*****@*****.**";
            user.RoleId    = Roles.User;
            user.IsActive  = true;
            new UserManager().Insert(apiContext, user);
        }
 // POST api/user
 public HttpResponseMessage Post(Models.UserInfo userinfo)
 {
     try
     {
         // Mark user InActive at creation, It would be activated later by email notification
         userinfo.IsActive = false;
         Entities.User user = userinfo;
         new Managers.UserManager().Insert(Context.GetContext(), user);
         return(Request.CreateResponse(HttpStatusCode.OK, "User Added Successfully"));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
예제 #4
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="id"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, int id, out Entities.User user)
        {
            // API doesn't allow null parameters.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (id == null)
            {
                throw new System.ArgumentNullException("id");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);
            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
                var qry = context.Users.Where(r => r.Id.Equals(id)).FirstOrDefault();

                // See what would be default value in this case
                // Also to see if no value found what shall be put into Action Result
                if (qry != null)
                {
                    user = qry;

                    // must detach the object before return
                    DetachObject(apiContext, user);
                }
                else
                {
                    user    = new Entities.User();
                    user.Id = id;

                    result.WasSuccessful = false;
                    result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Object not Found", Helpers.ActionResultMessageType.Warning));
                }
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.GetEntityException.Factory(ex);
            }

            return(result);
        }
예제 #5
0
        public Entities.User IsExists(ApiContext apiContext, string email, string password)
        {
            Entities.User user = null;

            var querySettings = QuerySettings <Entities.User> .Factory();

            querySettings.WhereExpression = e => e.Email == email && e.Password == password;

            CoreManagers.UserManager.IsExists(apiContext, querySettings.WhereExpression, out user);

            //Check if user is active or not
            if (user != null && !user.IsActive)
            {
                user = null;
            }

            return(user);
        }
예제 #6
0
        public static Helpers.ActionResult Add(Helpers.ApiContext apiContext, Entities.User user, out long id)
        {
            // API doesn't allow null parameters. This method requires at least 1 item in the collection.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (user == null)
            {
                throw new System.ArgumentNullException("image");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);

            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

                // ADD to context
                OnAdding(apiContext, user);

                context.AddObject("Users", user);

                context.SaveChanges();                 // Save Changes

                id = user.Id;

                DetachObjects(apiContext, new System.Collections.Generic.List <Entities.User> {
                    user
                });                                                                                                    // Clean ObjectState cache
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;                // Helpers.Exceptions.AddEntityException.Factory(ex);
            }

            return(result);
        }
예제 #7
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="whereClause"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool IsExists(Helpers.ApiContext apiContext, System.Linq.Expressions.Expression <System.Func <Entities.User, bool> > whereClause, out Entities.User entity)
        {
            // API doesn't allow null parameters. This method requires at least 1 item in the collection.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (whereClause == null)
            {
                throw new System.ArgumentNullException("whereClause");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);
            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;
                var query = context.Users.Where(whereClause).FirstOrDefault();

                if (query != null)
                {
                    entity = query;
                    DetachObject(apiContext, entity);     // must detach the object before return
                }
                else
                {
                    entity = null;
                }

                return(query != null);
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.ExistsException.Factory(ex);
            }
        }
예제 #8
0
 //	This partial method gives us a way to access an object after it has been purged from the system.
 static partial void OnPurged(Helpers.ApiContext apiContext, Entities.User user);
예제 #9
0
 //	This partial method gives us a way to access an object after it has been validated in the system.
 static partial void OnValidated(Helpers.ApiContext apiContext, Entities.User user, ref Helpers.ActionResult result);
예제 #10
0
 //	This partial method gives us a way to access an object during it is bulk updated in the system.
 static partial void OnPartialUpdate(Helpers.ApiContext apiContext, Entities.User user);
예제 #11
0
 //	This partial method gives us a way to update an object before it is imported into the system.
 static partial void OnImporting(Helpers.ApiContext apiContext, Entities.User user);
예제 #12
0
 //	This partial method gives us a way to access an object after it has been updated in the system.
 static partial void OnUpdated(Helpers.ApiContext apiContext, Entities.User user, bool isBulkUpdate);
예제 #13
0
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="user"></param>
        /// <param name="result"></param>
        public static void ValidateData(Helpers.ApiContext apiContext, Entities.User user, ref Helpers.ActionResult result)
        {
            OnValidating(apiContext, user, ref result);

            if (user.Id == null)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Id is required.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            if (!System.String.IsNullOrWhiteSpace(user.FirstName) && user.FirstName.Length > 50)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "FirstName must be 50 characters or less.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(user.FirstName) && !System.Text.RegularExpressions.Regex.IsMatch(user.FirstName, alphaNumeric))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "FirstName contains invalid characters.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(user.LastName) && user.LastName.Length > 50)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "LastName must be 50 characters or less.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(user.LastName) && !System.Text.RegularExpressions.Regex.IsMatch(user.LastName, alphaNumeric))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "LastName contains invalid characters.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (System.String.IsNullOrWhiteSpace(user.Email))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Email is required.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            if (!System.String.IsNullOrWhiteSpace(user.Email) && user.Email.Length > 50)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Email must be 50 characters or less.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(user.Email) && !System.Text.RegularExpressions.Regex.IsMatch(user.Email, alphaNumeric))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Email contains invalid characters.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (System.String.IsNullOrWhiteSpace(user.Password))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Password is required.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            if (!System.String.IsNullOrWhiteSpace(user.Password) && user.Password.Length > 50)
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Password must be 50 characters or less.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }
            if (!System.String.IsNullOrWhiteSpace(user.Password) && !System.Text.RegularExpressions.Regex.IsMatch(user.Password, alphaNumeric))
            {
                result.Messages.Add(Helpers.ActionResultMessage.Factory(user, "Password contains invalid characters.", Helpers.ActionResultMessageType.Error));
                result.WasSuccessful = false;
            }

            OnValidated(apiContext, user, ref result);
        }
 static partial void OnAdding(Helpers.ApiContext apiContext, Entities.User user)
 {
     user.CreatedOn = DateTime.Now;
     user.LastLogin = DateTime.Now;
 }