Exemple #1
0
        public ActionResult UploadEmployee(string id, HttpPostedFileBase[] files)
        {
            byte max     = 0;
            var  listImg = db.ImgEmps.Where(p => p.EmployeeCode == id).ToList();

            if (listImg.Count > 0)
            {
                max = listImg.Max(p => p.SortEmp);
            }
            var listFile = files.Where(p => p != null);

            foreach (var f in listFile)
            {
                var img = new ImgEmp();
                img.EmployeeCode = id;
                img.EmployeeImg  = f.FileName;
                img.SortEmp      = ++max;
                db.ImgEmps.Add(img);
                var path = Server.MapPath("~/ImgUI/Emp/" + f.FileName);
                f.SaveAs(path);
            }
            if (listFile.Any())
            {
                db.SaveChanges();
            }
            return(RedirectToAction("UploadEmployee"));
        }
Exemple #2
0
        private async void Submit(string obj)
        {
            try
            {
                var newemp = new Employee()
                {
                    Mission = Mission,
                    Address = Address,
                    Avatar  = ImgEmp.ConvertToByte(),
                    Name    = Name,
                    Salary  = Convert.ToDecimal(Salary),
                    Phone   = Phone,
                    DOB     = Convert.ToDateTime(DOB),
                };


                if (IsB)
                {
                    newemp.Sex = true;
                }
                if (IsG)
                {
                    newemp.Sex = false;
                }



                if (string.IsNullOrEmpty(obj))
                {
                    //Create new customer

                    var objresult = await employee_Repo.Add(newemp);

                    if (objresult != null)
                    {
                        dc = new DialogContent()
                        {
                            Content = "Thêm Thành Công", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);

                        ListEmployee.Add(objresult);
                    }
                    else
                    {
                        dc = new DialogContent()
                        {
                            Content = "Thêm Thất Bại", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);
                    }
                }
                else
                {
                    //update customer

                    newemp.EmpID = Convert.ToInt32(obj);

                    if (await employee_Repo.Update(newemp))
                    {
                        dc = new DialogContent()
                        {
                            Content = "Cập Nhật Thành Công", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);

                        ListEmployee = new ObservableCollection <Employee>(await employee_Repo.GetAllAsync());
                    }
                    else
                    {
                        dc = new DialogContent()
                        {
                            Content = "Cập Nhật Thất Bại", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);
                    }
                }
            }
            catch
            {
                dc.Content = "Có Lỗi";
                dc.Tilte   = "Thông Báo";
                dialog     = new DialogOk()
                {
                    DataContext = dc
                };
                DialogHost.CloseDialogCommand.Execute(null, null);
                await DialogHost.Show(dialog, DialogHostId);
            }
        }