コード例 #1
0
ファイル: UserOrange.aspx.cs プロジェクト: Slohar420/PMP
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        try
        {
            EmployeeUpdateReq objEmployeeReq = new EmployeeUpdateReq();

            objEmployeeReq.FullName     = txtFirstName.Text + " " + txtLastName.Text;
            objEmployeeReq.id           = hiddenID.Value;
            objEmployeeReq.EmployeeCode = txtEmployeecode.Text;
            objEmployeeReq.Desgination  = txtDesgination.Text;
            objEmployeeReq.JoningDate   = txtDOJ.Text;
            objEmployeeReq.Experince    = txtExperience.Text;
            objEmployeeReq.Skills       = txtSkills.Text;
            objEmployeeReq.Salary       = txtSallery.Text;
            objEmployeeReq.Email        = txtMailId.Text;
            objEmployeeReq.Role         = ddlType.SelectedItem.Text;
            objEmployeeReq.Password     = "******";
            if (txtDepartment.Text != "")
            {
                objEmployeeReq.DepartmetnID = txtDepartment.Text;
            }
            else
            {
                objEmployeeReq.DepartmetnID = ddlDepartment.SelectedItem.Value;
            }

            WebClient client = new WebClient();
            client.Headers[HttpRequestHeader.ContentType] = "text/json";

            DataContractJsonSerializer objJsonSerSend = new DataContractJsonSerializer(typeof(EmployeeUpdateReq));
            MemoryStream memStrToSend = new MemoryStream();
            objJsonSerSend.WriteObject(memStrToSend, objEmployeeReq);
            string data = Encoding.Default.GetString(memStrToSend.ToArray());

            string result = client.UploadString(URL + "/updateUser", "POST", data);

            bool response = JsonConvert.DeserializeObject <bool>(result);

            if (response)
            {
                clearAll();
                string add = "User Updated Successfully ! ";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Success('" + add + "');", true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "InCorrectUserName();", true);
            }
        }
        catch (Exception ex)
        {
            throw;
        }
    }
コード例 #2
0
        public async Task <HttpResponseMessage> Update(EmployeeUpdateReq req)
        {
            var obj = await employeeBE.GetById(req);

            if (obj == null)
            {
                return(this.ErrorResult(new Error(EnumError.EmployeeNotExist)));
            }

            Mapper.Map(req, obj);
            if (employeeBE.Update(obj))
            {
                return(this.OkResult());
            }
            else
            {
                return(this.ErrorResult(new Error(EnumError.UpdateFailse)));
            }
        }