lundi 1 avril 2019

ASP.NET MVC Check if there is a change in the model for an If statement

I am trying to put some validation logic into my controller but I'm having a little trouble.

Here's the code:

 if (holidayRequestForm.Approved == true)
            {
                TempData["msgAlreadyApproved"] = "This Holiday Has already been approved";
                return RedirectToAction("Index", "HolidayRequestFroms");
            }

My problem is I want to throw an error message for when a user attempts to approve a holiday request that has already been approved but obviously the code above will throw the message when any holiday get set to approved.

How would I go by checking if a change happens in the model and then throwing the temp message if no change has taking place.

thanks

Angular's ngIf showing else template before evaluating condition

I'm checking if there are any elements in array before showing them. If there aren't, a "not available" message should be displayed.

Class:

public lists = [];
public isLoading: boolean = false;

ngOnInit() {
  this.getLists()
}

getLists() {
  this.isLoading = true;
  this.list.getShoppingLists().subscribe(data => {
    this.isLoading = false;
    this.lists = data.data;
  });
}

Template:

<mat-spinner *ngIf="isLoading" class="mx-auto"></mat-spinner>

<div *ngIf="lists.length > 0; then withLists else withoutLists"></div>

<ng-template #withLists>
  <div *ngFor="let list of lists">
      <p></p>
  </div>
</ng-template>

<ng-template #withoutLists>
 <p>No lists available</p>
</ng-template>

The problem I have is that "not available" message shows in template whilst data is being returned from the API and it shouldn't. Any ideas why this is happening and how should I address this issue?

CodeIgniter showing different menu using If statement

I have an error in the variable when I try to get the value it says it was undefined While I have already stored the session of the variable "$level" and sent it to the view but the condition of the variable become undefined, is there anything wrong with the code?

The variable that I get is from the login. Also I have tried to call the $level and it work

I have tried to use foreach and non foreach method still none of these are working

View.php

<p>Number 1</p>
<?php if($level->level == '2') ?>
<p>Number 2</p>

admin.php

function index(){       
$level = $this->session->userdata('level');
$this->load->view('view',$level);
}

Login.php

public function do_login()
    {
        $u = $this->input->post("user");
        $p = md5($this->input->post("pass"));

        $cari = $this->model_pesawat->cek_login($u, $p)->row();
        $hitung = $this->model_pesawat->cek_login($u, $p)->num_rows();

        if ($hitung > 0) {

        $data = array('admin_id' => $cari->no_user ,
                            'admin_user' => $cari->username, 
                            'admin_nama' => $cari->nama,
                            'level' => $cari->level,
                            'admin_valid' => TRUE
            );

            $this->session->set_userdata($data);
            redirect('admin','refresh');
        }else{
            echo "maaf username atau password salah";
        }   
    }

I want the result the if statement will show different value in the view depending on the $level of the user

If-Else rules to hard code the parsing of an address

I want to start with a hard-coded, rule based structure in Python, preferably using IF-ELSE to solve the following:

For example, I have this properly formatted

UK postal address:
Flat 8, The Apartment, King Philip Street, SE1 3WX

The different variations that can be derived from the above Actual address are:

These ones focuses on the first line of the address variations:

Flat 8 - Actual
8
F8
f8
flat 8
flat8
FLAT8
FLAT 8

These ones focuses on second line of the address variations:

The Apartment - Actual
Apartment, 
TheApartment
theapartment
the apartment

These ones focuses on the third line of the address variations:

King Philip Street - Actual
King Philip St
King Philip st
King Philip street
King Philip STREET
king philip St
king philip st
king philip street
king philip STREET

These ones focuses on the fourth line of the address variations:

SE1 3WX - Actual
SE13WX
SE1 3WX
se1 3wx
se13wx

Hence, the Python function should be able to parse and output the above segmented results, once an address input into the function.

I have a few thousand addresses such as this to be parsed as well.

Has anyone done anything like this before, could someone please help to show me how this can be achieved ?

How can i test two Variables on NoneType in Python 3?

All the time I tried to compare two variables with type "None" but it doesn't work.

example:

if type(a and b) == type(None):
   #do something
else:
   #do other stuff

Does somebody know the right statement and an explanation?

CodeIgniter Javascript Onclick Not Working

I created a new option for my script on Admin->Users page. (and int type colum in users table.)

<li>
<?php if ($user->uyelik_tipi != "Bireysel"): ?>
 <a href="javascript:void(0)" onclick="kurumsal_onay(<?php echo $user->id; ?>);"><i class="fa fa-building option-icon"></i>Kurumsalı Onayla</a>
<?php endif; ?>
 </li>

This code in Admin_Controller.php page:

/*
Kurumsal Hesabı Onayla
*/
public function kurumsal_onay()
{
    $id = $this->input->post('id', true);
    $user = $this->auth_model->get_user($id);
    if ($this->auth_model->kurumsali_onayla($user)) {
        $this->session->set_flashdata('success', trans("msg_updated"));
    } else {
        $this->session->set_flashdata('error', trans("msg_error"));
    }
}

This code in Auth_Model.php:

//kurumsalı onayla
    public function kurumsali_onayla($user)
    {
        if (!empty($user)) {
            $data = array(
                'kurum_onay' => 1,

            );
            $this->db->where('id', $user->id);
            return $this->db->update('users', $data);
        }
        return false;
    }

But when i click to Link, nothing happens :/

Include #N/A value in IF syntax VBA

I have a problem including in my code the #N/A value in the cell. In my sheet, I want to eliminate the cell's content is the its value is either 0 or #N/A, but i don't know to write the VBA code for the #N/A.

This is the code that works for me, but it still gives an error when it encounters the #N/A cells.

For Each value In Sheets("Comments").Range("C2:Y600")
    If value = 0 Or value = "#N/A" Then
        value = " "
    End If
Next