コード例 #1
0
        public UserLoginDTO SaveData(UserLoginDTO model)
        {
            log.MethodStart();

            var          currentDateTime = DateTime.Now;
            var          currentUser     = "";
            UserLoginDTO objReturn       = new UserLoginDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objModel = new TCUserLogin();

                    if (model.usr_status == "E")
                    {
                        objModel = _db.TCUserLogins.FirstOrDefault(x => x.usr_username == model.usr_username);
                    }

                    if (model.usr_status == "N")
                    {
                        objModel = _mapper.Map <TCUserLogin>(model);

                        objModel.usr_status     = objModel.usr_active == true ? "A" : "I";
                        objModel.usr_createuser = model.usr_createuser;
                        objModel.usr_createdate = currentDateTime;

                        currentUser = objModel.usr_createuser;

                        objModel.usr_lockoutEndDateUtc = currentDateTime;

                        _db.TCUserLogins.Add(objModel);
                    }
                    else if (model.usr_status == "E")
                    {
                        objModel.usr_firstname = model.usr_firstname;
                        objModel.usr_lastname  = model.usr_lastname;
                        objModel.usr_email     = model.usr_email;
                        if (string.IsNullOrEmpty(model.usr_password) == false && model.usr_password != objModel.usr_password)
                        {
                            objModel.usr_password = model.usr_password;

                            objModel.usr_accessFailedCount = 0;
                            objModel.usr_lockoutEndDateUtc = currentDateTime;

                            _db.TCUserPasswordHistorys.Add(new TCUserPasswordHistory()
                            {
                                uph_username   = model.usr_username,
                                uph_password   = model.usr_password,
                                uph_status     = "A",
                                uph_active     = true,
                                uph_createuser = model.usr_username,
                                uph_createdate = currentDateTime
                            });
                        }
                        objModel.usr_active     = model.usr_active;
                        objModel.usr_status     = objModel.usr_active == true ? "A" : "I";
                        objModel.usr_updateuser = model.usr_updateuser;
                        objModel.usr_updatedate = currentDateTime;

                        currentUser = objModel.usr_updateuser;

                        //_db.TCHospitals.Update(objModel);
                    }

                    #region Save Log Process ...
                    _db.LogProcesss.Add(new LogProcess()
                    {
                        log_usr_id     = currentUser,
                        log_mnu_id     = "",
                        log_mnu_name   = "UserLogin",
                        log_tran_id    = objModel.usr_username,
                        log_action     = (model.usr_status == "N" ? "New" : "Update"),
                        log_desc       = (model.usr_status == "N" ? "New" : "Update") + " UserLogin " + objModel.usr_username,
                        log_createuser = currentUser,
                        log_createdate = currentDateTime
                    });
                    #endregion

                    _db.SaveChanges();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }

            log.MethodFinish();

            return(objReturn);
        }
コード例 #2
0
        public UserLoginPermissionDTO SaveData(UserLoginPermissionDTO model)
        {
            log.MethodStart();

            var currentDateTime = DateTime.Now;
            var currentUser     = "";
            UserLoginPermissionDTO objReturn = new UserLoginPermissionDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objModel = new TCUserLoginPermission();

                    if (model.usp_status == "E")
                    {
                        objModel = _db.TCUserLoginPermissions.FirstOrDefault(x => x.usp_id == model.usp_id);
                    }

                    if (model.usp_status == "N")
                    {
                        objModel = _mapper.Map <TCUserLoginPermission>(model);

                        objModel.usp_createdate = currentDateTime;
                        objModel.usp_status     = objModel.usp_active == true ? "A" : "I";

                        currentUser = objModel.usp_createuser;

                        _db.TCUserLoginPermissions.Add(objModel);
                    }
                    else if (model.usp_status == "E")
                    {
                        objModel.usp_rol_code   = model.usp_rol_code;
                        objModel.usp_arh_code   = model.usp_arh_code;
                        objModel.usp_hos_code   = model.usp_hos_code;
                        objModel.usp_active     = model.usp_active;
                        objModel.usp_status     = objModel.usp_active == true ? "A" : "I";
                        objModel.usp_updateuser = model.usp_updateuser;
                        objModel.usp_updatedate = currentDateTime;

                        currentUser = objModel.usp_updateuser;

                        //_db.TCHospitals.Update(objModel);
                    }

                    #region Save Log Process ...
                    _db.LogProcesss.Add(new LogProcess()
                    {
                        log_usr_id     = currentUser,
                        log_mnu_id     = "",
                        log_mnu_name   = "UserPermission",
                        log_tran_id    = objModel.usp_id.ToString(),
                        log_action     = (model.usp_status == "N" ? "New" : "Update"),
                        log_desc       = "Update UserPermission " + objModel.usp_usr_userName,
                        log_createuser = currentUser,
                        log_createdate = currentDateTime
                    });
                    #endregion

                    _db.SaveChanges();

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }

            log.MethodFinish();

            return(objReturn);
        }