Esempio n. 1
0
        public long AddEmployee(AddEmployeeRequest employee)
        {
            var newEmployee = mapper.Map <Employees>(employee);

            newEmployee.DateHired  = DateTime.Now;
            newEmployee.LastUpdate = DateTime.Now;

            context.Add(newEmployee);
            context.SaveChanges();
            return(newEmployee.Id);
        }
 public bool Delete(Employee employee)
 {
     try
     {
         _humanResourceContext.Employees.Remove(employee);
         _humanResourceContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);//Logger eklenicek
         return(false);
     }
 }
Esempio n. 3
0
        public async Task When_Get_Employees_Async_Then_Return_Full_List_Of_Employee()
        {
            // Arrange
            for (int i = 0; i < 5; i++)
            {
                context.Employees.Add(fixture.Build <Employee>().Without(x => x.Positions).Without(x => x.ManagerEmployee).Create());
                context.SaveChanges();
            }

            // Act
            var result = await sut.GetEmployeesAsync();

            // Assert
            result.Should().BeEquivalentTo(context.Employees);
        }
Esempio n. 4
0
        public string Post([FromBody] Workers value)
        {
            //First we need check User have existing in database
            if (!dbContext.Workers.Any(user => user.Login.Equals(value.Login)))
            {
                Workers user = new Workers();
                user.Login      = value.Login; // assign value from POST
                user.Name       = value.Name;
                user.Surname    = value.Surname;
                user.Sex        = value.Sex;
                user.Department = value.Department;
                user.Position   = value.Position;
                user.Salt       = Convert.ToBase64String(Common.GetRandomSalt(16)); //Get Random Salt
                user.Password   = Convert.ToBase64String(Common.SaltHashPassword(
                                                             Encoding.ASCII.GetBytes(value.Password),
                                                             Convert.FromBase64String(user.Salt)));

                //Add to Database
                try
                {
                    dbContext.Add(user);
                    dbContext.SaveChanges();
                    return(JsonConvert.SerializeObject("Register successfully"));
                }
                catch (Exception ex)
                {
                    return(JsonConvert.SerializeObject(ex.Message));
                }
            }
            else
            {
                return(JsonConvert.SerializeObject("User is existing in Database"));
            }
        }
Esempio n. 5
0
 public string Post([FromBody] Workers value)
 {
     if (dbContext.Workers.Any(user => user.Login.Equals(value.Login)))
     {
         Workers user = dbContext.Workers.Where(u => u.Login.Equals(value.Login)).First();
         try
         {
             dbContext.Workers.Remove(user);
             user.Login      = value.Login; // assign value from POST
             user.Name       = value.Name;
             user.Surname    = value.Surname;
             user.Sex        = value.Sex;
             user.Department = value.Department;
             user.Position   = value.Position;
             user.Salt       = Convert.ToBase64String(Common.GetRandomSalt(16)); //Get Random Salt
             user.Password   = Convert.ToBase64String(Common.SaltHashPassword(
                                                          Encoding.ASCII.GetBytes(value.Password),
                                                          Convert.FromBase64String(user.Salt)));
             dbContext.Add(user);
             dbContext.SaveChanges();
             return(JsonConvert.SerializeObject("Update successfully"));
         }
         catch (Exception ex)
         {
             return(JsonConvert.SerializeObject(ex.Message));
         }
     }
     else
     {
         return(JsonConvert.SerializeObject("User is not existing"));
     }
 }
        public ActionResult SendMessage(Message m, FormCollection fc)
        {
            string Role                  = fc["Role"];
            string Id                    = fc["EmpId"];
            string newpassword           = fc["Password"];
            int    EmpId                 = Convert.ToInt32(Id);
            HumanResourceContext context = new HumanResourceContext();

            context.MessageSet.Add(m);
            context.SaveChanges();
            var senderEmail1  = "";
            var staffpassword = "";

            if (Role != "Admin")
            {
                senderEmail1  = "*****@*****.**";
                staffpassword = newpassword;
            }
            else
            {
                senderEmail1  = "*****@*****.**";
                staffpassword = "******";
            }
            try
            {
                if (ModelState.IsValid)
                {
                    var senderEmail   = senderEmail1;
                    var receiverEmail = m.email;
                    var password      = staffpassword;
                    var sub           = m.subject;
                    var body          = m.message;
                    var smtp          = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new NetworkCredential(senderEmail, password)
                    };
                    using (var mess = new MailMessage(senderEmail, receiverEmail)
                    {
                        Subject = sub,
                        Body = body
                    })
                    {
                        smtp.Send(mess);
                    }
                    return(View(m));
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "Some Error";
            }
            return(View());
        }
        public ActionResult Index(Employees employee, HttpPostedFileBase image, HttpPostedFileBase Resume)
        {
            HumanResourceContext context = new HumanResourceContext();

            if (Resume != null)
            {
                Resume.SaveAs(Path.Combine(Server.MapPath("~/Resume"), Resume.FileName));
                employee.Resume = "~/Resume/" + Resume.FileName;
            }
            if (image != null)
            {
                image.SaveAs(HttpContext.Server.MapPath("~/Image/") + image.FileName);
                employee.Photo = "~/Image/" + image.FileName;
            }
            employee.Resume = employee.Resume.Replace("~", string.Empty);
            employee.Photo  = employee.Photo.Replace("~", string.Empty);
            context.Employeeset.Add(employee);
            context.SaveChanges();
            ModelState.Clear();
            return(View("Detail", employee));
        }
Esempio n. 8
0
 public string Post([FromBody] Workers value)
 {
     if (dbContext.Workers.Any(user => user.Id.Equals(value.Id)))
     {
         Workers user = dbContext.Workers.Where(u => u.Id.Equals(value.Id)).First();
         try
         {
             dbContext.Workers.Remove(user);
             dbContext.SaveChanges();
             return(JsonConvert.SerializeObject("Delete successfully"));
         }
         catch (Exception ex)
         {
             return(JsonConvert.SerializeObject(ex.Message));
         }
     }
     else
     {
         return(JsonConvert.SerializeObject("User is not existing"));
     }
 }
 public ActionResult Edit([Bind(Include = "EmpId,Name,MiddleName,LastName,PhoneNumber,EmailAddress,Salary,IsContract,Photo,Department,Resume,Address,Sex,MaritalStatus,StartDate,Education,NRC,Manager,Birthday,SpousePh,SpouseName,Position,ContactName,ContactPh")] Employees employee, HttpPostedFileBase image, HttpPostedFileBase Resume)
 {
     if (ModelState.IsValid)
     {
         HumanResourceContext context = new HumanResourceContext();
         if (Resume != null)
         {
             Resume.SaveAs(Path.Combine(Server.MapPath("~/Resume"), Resume.FileName));
             employee.Resume = "~/Resume/" + Resume.FileName;
             employee.Resume = employee.Resume.Replace("~", string.Empty);
         }
         if (image != null)
         {
             image.SaveAs(HttpContext.Server.MapPath("~/Image/") + image.FileName);
             employee.Photo = "~/Image/" + image.FileName;
             employee.Photo = employee.Photo.Replace("~", string.Empty);
         }
         context.Entry(employee).State = EntityState.Modified;
         context.SaveChanges();
         return(RedirectToAction("EmployeeList", "HumanResource"));
     }
     return(View(employee));
 }