Exemplo n.º 1
0
        public PostResponse <Employee> AddOrUpdateEmployeeWithPhoto(EmployeeAddOrUpdateRequest req)
        {
            PostResponse <Employee> response;
            var headers = SessionHelper.GetAuthorizationHeadersForUser();
            PostWebServiceResponse webResponse = _employeeRepository.AddOrUpdateEmployeeWithImage(req.empData, req.fileName, req.imageData, headers);

            response          = CreateServiceResponse <PostResponse <Employee> >(webResponse);
            response.recordId = webResponse.recordId;
            return(response);
        }
Exemplo n.º 2
0
        protected void SaveNewRecord(object sender, DirectEventArgs e)
        {
            //Getting the id to check if it is an Add or an edit as they are managed within the same form.
            string id = e.ExtraParams["id"];

            string   obj = e.ExtraParams["values"];
            Employee b   = JsonConvert.DeserializeObject <Employee>(obj);

            b.name = new EmployeeName()
            {
                firstName = firstName.Text, lastName = lastName.Text, familyName = familyName.Text, middleName = middleName.Text
            };
            b.isInactive = isInactive.Checked;
            b.recordId   = id;
            // Define the object to add or edit as null
            if (branchId.SelectedItem != null)
            {
                b.branchName = branchId.SelectedItem.Text;
            }
            if (departmentId.SelectedItem != null)
            {
                b.departmentName = departmentId.SelectedItem.Text;
            }
            if (positionId.SelectedItem != null)
            {
                b.positionName = positionId.SelectedItem.Text;
            }
            b.name.fullName = b.name.firstName + " " + b.name.middleName + " " + b.name.lastName + " ";
            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    EmployeeAddOrUpdateRequest request = new EmployeeAddOrUpdateRequest();

                    byte[] fileData = null;
                    if (picturePath.PostedFile != null && picturePath.PostedFile.ContentLength > 0)
                    {
                        using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        {
                            fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        }
                        request.fileName  = picturePath.PostedFile.FileName;
                        request.imageData = fileData;
                    }
                    else
                    {
                        request.imageData = fileData;
                        request.fileName  = "";
                    }
                    request.empData = b;



                    PostResponse <Employee> r = _employeeService.AddOrUpdateEmployeeWithPhoto(request);
                    b.recordId = r.recordId;

                    //check if the insert failed
                    if (!r.Success)//it maybe be another condition
                    {
                        //Show an error saving...
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, r.Summary).Show();
                        return;
                    }
                    else
                    {
                        //Add this record to the store
                        this.Store1.Insert(0, b);

                        //Display successful notification
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });

                        this.EditRecordWindow.Close();
                        RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel;
                        sm.DeselectAll();
                        sm.Select(b.recordId.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Error exception displaying a messsage box
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show();
                }
            }
            else
            {
                //Update Mode

                try
                {
                    int index = Convert.ToInt32(id);//getting the id of the record
                    EmployeeAddOrUpdateRequest request = new EmployeeAddOrUpdateRequest();

                    byte[] fileData = null;
                    if (picturePath.HasFile && picturePath.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        // {
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        // }
                        fileData          = new byte[picturePath.PostedFile.ContentLength];
                        fileData          = picturePath.FileBytes;
                        request.fileName  = picturePath.PostedFile.FileName;
                        request.imageData = fileData;
                    }
                    else
                    {
                        request.imageData = fileData;
                        request.fileName  = "";
                    }
                    request.empData = b;



                    PostResponse <Employee> r = _employeeService.AddOrUpdateEmployeeWithPhoto(request);

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!r.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                        return;
                    }
                    else
                    {
                        ModelProxy record = this.Store1.GetById(index);
                        //BasicInfoTab.UpdateRecord(record);
                        record.Set("branchName", b.branchName);
                        record.Set("departmentName", b.departmentName);
                        record.Set("positionName", b.positionName);
                        record.Set("name", b.name);
                        record.Set("reference", b.reference);
                        record.Set("hireDate", b.hireDate.Value.ToShortDateString());
                        record.Commit();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });

                        this.EditRecordWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }