public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var employeer = await _context.Employeers.FindAsync(request.Employeer.EmployeerId);

                if (employeer == null)
                {
                    employeer = new Employeer();
                    await _context.Employeers.AddAsync(employeer, cancellationToken);
                }

                employeer.FirstName = request.Employeer.FirstName;

                employeer.LastName = request.Employeer.LastName;

                employeer.Email = request.Employeer.Email;

                await _context.SaveChangesAsync(cancellationToken);

                if (request.Employeer.EmployeerId == default)
                {
                    await _mediator.Publish(new EmployeerCreatedEvent(employeer), cancellationToken);
                }

                return(new Response()
                {
                    Employeer = employeer.ToDto()
                });
            }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HumanResourcesDepartment.Menu menu = new HumanResourcesDepartment.Menu();
                this.company = menu.LoadObject("Google", Server.MapPath(@"~\App_Data"));
                ArrayList positions = new ArrayList();
                positions.Add("Product owner");
                positions.Add("Developer");
                positions.Add("QA");
                positions.Add("Project manager");
                positions.Add("Business analyst");

                Position.DataSource = positions;
                Position.DataBind();
                Employeer.DataSource     = this.ReturnEmployerList(this.company);
                Employeer.DataValueField = "Key";
                Employeer.DataTextField  = "Value";
                Employeer.DataBind();
                Subdivision.DataSource = this.ReturnSubdivisions(this.company);
                Subdivision.DataBind();
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    this.id = int.Parse(Request.QueryString["id"]);
                    this.SetDataOnForm(id);
                    this.ChangeButtons();
                }
            }
            else
            {
                HumanResourcesDepartment.Menu menu = new HumanResourcesDepartment.Menu();
                this.company = menu.LoadObject("Google", Server.MapPath(@"~\App_Data"));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Employeerid,Name,Email,Contact,recuritment,No_ofPost")] Employeer employeer)
        {
            if (id != employeer.Employeerid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employeer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeerExists(employeer.Employeerid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeer));
        }
Exemple #4
0
 public ActionResult AddEmployeer(Employeer model)
 {
     using (ApplicationContext db = new ApplicationContext())
     {
         if (User.Identity.IsAuthenticated && db.Users.FirstOrDefault(elem => elem.UserName == User.Identity.Name).MyRole == MyRoles.Admin)
         {
             try
             {
                 if (db.Employeers.FirstOrDefault(elem => elem.Email == model.Email) == null)
                 {
                     db.Employeers.Add(new Employeer()
                     {
                         Email = model.Email, Name = model.Name, Phone = model.Phone
                     });
                 }
                 else
                 {
                     ViewBag.Error = "Email is in db";
                     return(View());
                 }
                 db.SaveChanges();
                 return(RedirectToAction("Employeers", "Auto", new { area = "Admin" }));
             }
             catch
             {
                 ViewBag.Error = "Unknow mistake";
                 return(View());
             }
         }
         else
         {
             return(RedirectToAction("Index", "Home", new { area = "" }));
         }
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Employeer employeer = db.Employeers.Find(id);

            db.Employeers.Remove(employeer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private static bool CheckForValidEmployeer(Employeer employeer)
        {
            if (!Enum.IsDefined(typeof(Employeer), employeer))
            {
                return(false);
            }

            return(true);
        }
 public static EmployeerDto ToDto(this Employeer employeer)
 {
     return(new EmployeerDto
     {
         EmployeerId = employeer.EmployeerId,
         Email = employeer.Email,
         FirstName = employeer.FirstName,
         LastName = employeer.LastName,
     });
 }
 public ActionResult Edit([Bind(Include = "employeerId,lastName,firstName")] Employeer employeer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employeer));
 }
Exemple #9
0
        public ActionResult DetailsEmployer(int id)
        {
            if (!CheckIfAdmin())
            {
                return(RedirectToAction("ErrorPage"));
            }
            Employeer employer = _sqlConnection.GetEmployer(id);

            return(View(employer));
        }
Exemple #10
0
        public ActionResult About(int id)
        {
            if (!CheckIsLogin())
            {
                return(RedirectToAction("ErrorPage", "Admin"));
            }
            Employeer employer = _sqlConnection.GetEmployer(id);

            return(View(employer));
        }
        public async Task <IActionResult> Create([Bind("Employeerid,Name,Email,Contact,recuritment,No_ofPost")] Employeer employeer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeer));
        }
        public ActionResult Create([Bind(Include = "employeerId,lastName,firstName")] Employeer employeer)
        {
            if (ModelState.IsValid)
            {
                db.Employeers.Add(employeer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employeer));
        }
Exemple #13
0
        public void Update(Employeer empl)
        {
            var emp = Get(empl.ID);

            if (emp != null)
            {
                emp.Name        = empl.Name;
                emp.Surname     = empl.Surname;
                emp.Description = empl.Description;
                emp.Date        = empl.Date;
            }
        }
Exemple #14
0
        public ActionResult Add(Employeer employer)
        {
            if (!CheckIfAdmin())
            {
                return(RedirectToAction("ErrorPage"));
            }

            employer.ContractType = _sqlConnection.GetContractType(employer.ContractType.Id);
            employer.Workplace    = _sqlConnection.GetWorkplace(employer.Workplace.Id);
            _sqlConnection.CreateEmployer(employer);

            return(RedirectToAction("EmployerList"));
        }
        // GET: Employeers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Employeer employeer = db.Employeers.Find(id);

            if (employeer == null)
            {
                return(HttpNotFound());
            }
            return(View(employeer));
        }
Exemple #16
0
        static void Main(string[] args)
        {
            Employeer employeer = new Employeer()
            {
                Email       = "*****@*****.**",
                Id          = Guid.NewGuid(),
                MonthHours  = 220,
                MonthSalary = 2500,
                Name        = "Ben Jhonson"
            };

            Console.WriteLine($"Amount salary: {SalaryEmployeerCalculator.Calculate(employeer, 200):C2}.");
            ProccessPaymentSalary.Proccess(employeer);
            SendEmail.Send(employeer.Email, "Your salary was paid.");
        }
Exemple #17
0
        public IActionResult Delete(int id)
        {
            //Физическая модель и модель представления должны быть разделены
            Employeer emp = _EmployeesData.Get(id);

            return(View(new EmployeerViewModel()
            {
                ID = emp.ID,
                Date = emp.Date,
                Description = emp.Description,
                Name = emp.Name,
                Surname = emp.Surname
            }));

            ;
        }
Exemple #18
0
        //The Employeer class do too much things.
        //A good method is separate responsabilities, like a Email class and a salary calculator class.

        static void Main(string[] args)
        {
            Employeer employeer = new Employeer()
            {
                Email       = "*****@*****.**",
                Id          = Guid.NewGuid(),
                MonthHours  = 220,
                MonthSalary = 2500,
                Name        = "Ben Jhonson"
            };

            employeer.CalculateSalary(200);
            employeer.ProcessPayment();
            employeer.SendEmailEmployeerSalary();
            Console.ReadLine();
        }
Exemple #19
0
        public ActionResult AddEmployeer(Employeer employeer)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Market.Employeers.Add(employeer);
                actionResult.Result            = $"{employeer.name + " " + employeer.surname} added with {employeer.salary} salary";
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Exemple #20
0
        public ActionResult CreateEmployer()
        {
            if (!CheckIfAdmin())
            {
                return(RedirectToAction("ErrorPage"));
            }

            Employeer employeer = new Employeer();

            employeer.Medical      = new Medical();
            employeer.ContractType = new ContractType();
            employeer.Holiday      = new Holiday();
            employeer.Hours        = new Hours();
            employeer.Salary       = new Salary();
            employeer.Workplace    = new Workplace();


            return(View(employeer));
        }
Exemple #21
0
        public Person CreatePerson(string first, string last, bool isSupervisor)
        {
            Person ret = null;

            if (!string.IsNullOrEmpty(first))
            {
                if (isSupervisor)
                {
                    ret = new Supervisor();
                }
                else
                {
                    ret = new Employeer();
                }

                ret.FirstName = first;
                ret.LastName  = last;
            }
            return(ret);
        }
Exemple #22
0
        public async Task <IActionResult> EditEmployeer(Employeer employeer)
        {//TODO: добавить выбор роли текстом
            var employeerDb = await db.Employeers.Include(e => e.Role).FirstOrDefaultAsync(r => r.Id == employeer.Id);

            employeerDb.Name           = employeer.Name;
            employeerDb.RoleId         = employeer.RoleId;
            employeerDb.Specialization = employeer.Specialization;
            employeerDb.Percent        = employeer.Percent;
            employeerDb.INN            = employeer.INN;
            await db.SaveChangesAsync();

            ViewBag.Spetializations = new SelectList(StaticValues.MasterSpecializations);
            ViewBag.EmployeerSum    = await db.Receipts.Include(e => e.Employeer)
                                      .Where(r => r.Employeer.Name == employeer.Name && r.Status == "Выдано")
                                      .Select(r => r.TotalPrice).SumAsync();

            ViewBag.EmployeerSalary = (double)ViewBag.EmployeerSum * (employeer.Percent / 100);
            ViewBag.ReceiptsCount   = await db.Receipts.Include(e => e.Employeer).Where(r => r.Employeer.Name == employeer.Name && r.Status == "Выдано").CountAsync();

            return(View(employeer));
        }
Exemple #23
0
        /// <summary>
        /// Отвечает за списание средств со счёта сотрудника
        /// </summary>
        /// <param name="employeer">Объект сотрудника</param>
        /// <param name="sum">Сумма списания</param>
        public async Task <IActionResult> Salary(Employeer employeer, decimal sum)
        {
            var emp = await db.Employeers.Include(e => e.Role).FirstOrDefaultAsync(e => e.Email == User.Identity.Name);

            ViewBag.EmployeerSum = await db.Receipts.Include(e => e.Employeer).Where(r => r.Employeer.Name == employeer.Name && r.Status == "Выдано").Select(r => r.TotalPrice).SumAsync();

            ViewBag.EmployeerSalary = (double)ViewBag.EmployeerSum * (employeer.Percent / 100);
            ViewBag.ReceiptsCount   = await db.Receipts.Include(e => e.Employeer).Where(r => r.Employeer.Name == employeer.Name && r.Status == "Выдано").CountAsync();

            if (emp.Balance >= sum && sum > 0)
            {
                emp.Balance -= sum;
                await db.SaveChangesAsync();
            }
            else
            {
                ModelState.AddModelError("", "Суммы на вашем счёте недостаточно");
                return(View("MyAccount", emp));
            }
            return(View("MyAccount", emp));
        }
Exemple #24
0
        private void PrintEmployeeList(List <Employee> list)
        {
            int i = 0;

            EmployeeDataGrid.Rows.Clear();
            if (EmployeeDataGrid.Columns.Count != 3)
            {
                EmployeeDataGrid.Columns.Clear();
                EmployeeDataGrid.Columns.Add("Id", "Id");
                EmployeeDataGrid.Columns.Add("EmployeeName", "Name");
                EmployeeDataGrid.Columns.Add("Payment", "Payment");
            }

            foreach (var Employeer in list)
            {
                EmployeeDataGrid.Rows.Add();
                EmployeeDataGrid.Rows[i].Cells[0].Value = Employeer.Id;
                EmployeeDataGrid.Rows[i].Cells[1].Value = Employeer.Name;
                EmployeeDataGrid.Rows[i].Cells[2].Value = Employeer.GetAverageSalary();
                i++;
            }
        }
Exemple #25
0
        public async Task <IActionResult> Edit(Employeer employeer, string NewPass)
        {
            employeer.Role = StaticValues.Master;
            var emp = await db.Employeers.Include(e => e.Role).FirstOrDefaultAsync(e => e.Email == User.Identity.Name);

            if (!string.IsNullOrWhiteSpace(NewPass))
            {
                if (emp.Password != employeer.Password)
                {
                    ModelState.AddModelError("", "Пароль неверен");
                    return(View(emp));
                }
                emp.Email    = employeer.Email;
                emp.Password = NewPass;
            }
            emp.Name           = employeer.Name;
            emp.INN            = employeer.INN;
            emp.Specialization = employeer.Specialization;
            await db.SaveChangesAsync();

            return(RedirectToAction("MyAccount"));
        }
Exemple #26
0
 public void Add(Employeer empl)
 {
     _Employees.Add(empl);
 }
 public static decimal Calculate(Employeer employeer, int currentMonthHoursWorked)
 {
     return((employeer.MonthSalary / employeer.MonthHours) * currentMonthHoursWorked);
 }
Exemple #28
0
 public EmployeerBuilder()
 {
     _employeer = new Employeer();
 }
 public static void Proccess(Employeer employeer)
 {
     Console.WriteLine($"Processing payment of {employeer.Name}...");
     Console.WriteLine("Completed.");
     return;
 }
 public EmployeerCreatedEvent(Employeer employeer)
 {
     Employeer = employeer;
 }