예제 #1
0
        public OperationStatus ChangePassWord(ChangePasswordDto passwordDto, string userName)
        {
            var result = new OperationStatus();

            if (String.IsNullOrWhiteSpace(passwordDto.OldPassword))
            {
                result.Status  = false;
                result.Message = "You must enter your old password";
                return(result);
            }

            if (String.IsNullOrWhiteSpace(passwordDto.NewPassword))
            {
                result.Status  = false;
                result.Message = "The new password cannot be blank";
                return(result);
            }

            if (passwordDto.NewPassword != passwordDto.NewPasswordConfirm)
            {
                result.Status  = false;
                result.Message = "The new password is not the same as the confirmation password.";
                return(result);
            }

            var existingPassword = string.Empty;

            using (var context = new CurrencyExposureContext())
            {
                existingPassword = context.User.Single(u => u.EmailAddress == userName).Password;
            }

            if (passwordDto.OldPassword != existingPassword)
            {
                result.Status  = false;
                result.Message = "The old password is incorrect";
                return(result);
            }

            using (var context = new CurrencyExposureContext())
            {
                var user = context.User.Single(u => u.EmailAddress == userName);
                user.Password = passwordDto.NewPassword;
                context.User.Attach(user);
                context.Entry(user).State = EntityState.Modified;
                context.SaveChanges();
            }

            result.Status  = true;
            result.Message = "Password has been successfully changed.";
            return(result);
        }
예제 #2
0
 public void SaveLoginAudit(string userName)
 {
     using (var context = new CurrencyExposureContext())
     {
         var audit = new Audit
         {
             UserName  = userName,
             AuditType = AuditType.UserLogin
         };
         context.Audit.Add(audit);
         context.SaveChanges();
     }
 }
예제 #3
0
        public OperationStatus SaveBill(Bill bill)
        {
            var result = new OperationStatus <User>();

            try
            {
                using (var context = new CurrencyExposureContext())
                {
                    context.Bill.Remove(context.Bill.First(c => c.Id == bill.Id));
                    context.Bill.Add(bill);
                    context.SaveChanges();
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.CreateFromException("Failed to Save Bill", ex);
                return(result);
            }
            return(result);
        }
예제 #4
0
        public OperationStatus SaveBills(List <Bill> bills, string organisationId)
        {
            var result = new OperationStatus <User>();

            try
            {
                using (var context = new CurrencyExposureContext())
                {
                    context.Bill.RemoveRange(context.Bill.Where(c => c.Id > 0 && c.OrganisationId == organisationId));
                    context.Bill.AddRange(bills);
                    context.SaveChanges();
                }
                result.Status = true;
            }
            catch (Exception ex)
            {
                result.CreateFromException("Failed to Save Bills", ex);
                return(result);
            }
            return(result);
        }