/* Create User */
        public async Task<OpObject> Create(CCustomer CustomerInfo, Boolean Confirmed = false)
        {
            /* Always cast to lowercase, f**k all */
            String LowerEmail = CustomerInfo.Email.ToLower();
            String EncryptedEmail = Encryptor.EncryptToString(LowerEmail);

            /* Check for dublets of email */
            var UserCheck = await (from Obj in Database.UserViews
                                   where Obj.Email == EncryptedEmail
                                   select Obj).FirstOrDefaultAsync();

            /* Did it exist? */
            if (UserCheck != null)
                return new OpObject(StatusCode.EntryExists, UserCheck.MasterId.ToString());

            /* Nah, lets create it */
            User nUser = new User
            {
                Email = EncryptedEmail,
                Password = Hasher.HashString(CustomerInfo.Password, EncryptedEmail),
                FirstName = Encryptor.EncryptToString(CustomerInfo.FirstName),
                LastName = Encryptor.EncryptToString(CustomerInfo.LastName),
                Phone = Encryptor.EncryptToString(CustomerInfo.Phone),
                Confirmed = Confirmed,
                Permissions = 0
            };

            /* Insert */
            Database.Users.Add(nUser);

            /* Set as added */
            Database.Entry(nUser).State = System.Data.Entity.EntityState.Added;

            /* Save database */
            await Database.SaveChangesAsync();

            /* Send back guid */
            return new OpObject(StatusCode.Ok, nUser.MasterId.ToString());
        }
Esempio n. 2
0
        /* Create User */
        public async Task<OpObject> CreateUser(CCustomer CustomerInfo)
        {
            /* Create return object */
            IsolatedContext IsoContext = new IsolatedContext();

            /* Execute function */
            return await Execute(new Func<Task>(async () =>
            {
                using (UserRepository UserRepo = new UserRepository())
                {
                    /* Done */
                    IsoContext.RetObj = await UserRepo.Create(CustomerInfo, true);

                    /* Sanity */
                    if (IsoContext.RetObj.Code != StatusCode.Ok)
                        return;

                    /* Create a confirmation code and send the email 
                     * to the given user */
                    using (MaintienceRepository MainRepo = new MaintienceRepository()) {
                        /* Create a new confcode */
                        String uId = (String)IsoContext.RetObj.Data;
                        String ConfCode = await MainRepo.CreateCode(CodeType.Confirmation, uId);

                        /* Send a new mail */
                        IsoContext.RetObj = await MainRepo.InsertMail(new CMail() {
                            MailTo = CustomerInfo.Email,
                            Type = MailType.NoReply,
                            Subject = "NRG Models Confirmation",
                            Body = "",
                            IsHtml = false
                        });
                    }
                }
            }), IsoContext);
        }
        /* Get Info */
        public async Task<OpObject> Get(String uGuid)
        {
            /* Get masterid */
            Int64 UserMasterId = Int64.Parse(uGuid);

            /* Check for user */
            var UserCheck = await (from Obj in Database.Users
                                   where (Obj.MasterId == UserMasterId && Obj.Deleted == false)
                                   select Obj).FirstOrDefaultAsync();

            /* Convert */
            CCustomer cCust = new CCustomer()
            {
                Guid = UserCheck.MasterId.ToString(),
                Email = Encryptor.DecryptString(UserCheck.Email),
                FirstName = Encryptor.DecryptString(UserCheck.FirstName),
                LastName = Encryptor.DecryptString(UserCheck.LastName),
                VatId = UserCheck.LastName
            };

            /* Done! */
            return new OpObject(StatusCode.Ok, cCust);
        }