Example #1
0
        private AccountMaster MapAccountMasterForCreate(UserMasterVM userMaster)
        {
            AccountMaster accountMaster = new AccountMaster();

            accountMaster.Name = userMaster.Name;
            accountMaster.OpeningBalanceType = userMaster.OpeningBalanceType;
            accountMaster.Date = userMaster.OpeningBalanceDate;
            if (userMaster.OpeningBalance != null)
            {
                accountMaster.OpeningBalance = userMaster.OpeningBalance.Value;
            }
            accountMaster.CreatedBy       = userMaster.CreatedBy.GetValueOrDefault();
            accountMaster.CreatedDateTime = userMaster.CreatedDateTime.GetValueOrDefault();


            var agm =
                context.AccountGroupMasters.FirstOrDefault(
                    x => context.AccountTypeMasters.Where(atm => atm.Name.ToLower().Equals("expenses"))
                    .Select(a => a.PKID)
                    .Contains(x.AccountTypeFKID));

            if (agm != null)
            {
                accountMaster.AccountTypeFKID  = agm.AccountTypeFKID;
                accountMaster.AccountGroupFKID = agm.PKID;
            }
            else
            {
                var atm = context.AccountTypeMasters.Where(x => x.Name.ToLower().Equals("expenses"))
                          .Select(a => a.PKID).FirstOrDefault();
                accountMaster.AccountTypeFKID = atm;
            }
            return(accountMaster);
        }
Example #2
0
        public UserLoginVM ValidateUser(string userName, string password)
        {
            IUserModuleEntitlements userModuleEntitlements = new UserModuleEntitlements();

            UserLoginVM  loginVM    = new UserLoginVM();
            UserMasterVM usermaster = Mapper.Map <UserMaster, UserMasterVM> (context.UserMasters.FirstOrDefault(x => x.LoginID.ToLower().Equals(userName.ToLower()) && x.Password.Equals(password)));

            loginVM = Mapper.Map <UserMasterVM, UserLoginVM>(usermaster);
            if (loginVM != null)
            {
                loginVM.UserModuleEntitlement = userModuleEntitlements.GetEntitlements((int)loginVM.PKID);
            }
            return(loginVM);
        }
Example #3
0
        public UserMasterVM UpdateUser(UserMasterVM userMaster)
        {
            userMaster.ModifiedDateTime = DateTime.Now;
            AccountMaster accountMaster = MapAccountMasterForUpdate(userMaster);

            try
            {
                context.Entry(accountMaster).State = EntityState.Modified;

                context.Entry(Mapper.Map <UserMasterVM, UserMaster>(userMaster)).State = EntityState.Modified;

                context.SaveChanges();
                return(userMaster);
            }
            catch (Exception ex)
            {
                throw new Exception("Update user Failed");
            }
        }
Example #4
0
        private AccountMaster MapAccountMasterForUpdate(UserMasterVM userMaster)
        {
            AccountMaster accountMaster =
                context.AccountMasters.FirstOrDefault(x => x.PKID == userMaster.AccountFKID.Value);

            if (accountMaster != null)
            {
                accountMaster.Name = userMaster.Name;
                accountMaster.OpeningBalanceType = userMaster.OpeningBalanceType;
                accountMaster.Date = userMaster.OpeningBalanceDate;
                if (userMaster.OpeningBalance != null)
                {
                    accountMaster.OpeningBalance = userMaster.OpeningBalance.Value;
                }
                accountMaster.ModifiedBy       = userMaster.ModifiedBy.GetValueOrDefault();
                accountMaster.ModifiedDateTime = userMaster.ModifiedDateTime.GetValueOrDefault();
                return(accountMaster);
            }
            return(new AccountMaster());
        }
Example #5
0
        public UserMasterVM CreateUser(UserMasterVM userMaster)
        {
            userMaster.CreatedDateTime = DateTime.Now;
            AccountMaster accountMaster = MapAccountMasterForCreate(userMaster);

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    context.AccountMasters.Add(accountMaster);
                    context.SaveChanges();

                    userMaster.AccountFKID = accountMaster.PKID;
                    context.UserMasters.Add(Mapper.Map <UserMasterVM, UserMaster>(userMaster));
                    context.SaveChanges();
                    scope.Complete();
                    return(userMaster);
                }
                catch (Exception ex)
                {
                    throw new Exception("Save user Failed");
                }
            }
        }
Example #6
0
 public UserMasterVM Put(UserMasterVM userMasterVm)
 {
     return(userMaster.UpdateUser(userMasterVm));
 }
Example #7
0
 public UserMasterVM Post(UserMasterVM userMasterVm)
 {
     return(userMaster.CreateUser(userMasterVm));
 }