Beispiel #1
0
        public ActionResult Add(Employee employee)
        {
            db.Employees.Add(employee);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
    public ActionResult Add(Employee employee)  // Model binding
    {
        db.Employees.Add(employee);
        db.SaveChanges();

        return(RedirectToAction(nameof(Index)));
    }
Beispiel #3
0
 public ActionResult Add(Department departments)
 {
     db.Departments.Add(departments);
     db.SaveChanges();
     // return Redirect("/employee");
     return(RedirectToAction(nameof(Index)));
 }
        public IActionResult Create(Registration registration)
        {
            ViewData["TestId"] = new SelectList(_context.Test, "Id", "Id", registration.TestId);

            Student student = new Student
            {
                Name       = registration.Student.Name,
                FatherName = registration.Student.FatherName,
                Phone      = registration.Student.Phone,
                Email      = registration.Student.Email,
                Nid        = registration.Student.Nid,
                EnteryDate = DateTime.Now
            };

            _context.Add(student);
            _context.SaveChanges();

            Registration _registration = new Registration()
            {
                StudentId = student.Id
            };

            _context.Add(_registration);
            _context.SaveChanges();


            _context.Add(registration);
            _context.SaveChanges();

            return(View());
        }
    public ActionResult Add(Department department)  // Model binding
    {
        db.Departments.Add(department);
        db.SaveChanges();

        return(RedirectToAction(nameof(Index)));
    }
Beispiel #6
0
    public ActionResult Add([FromForm] Department department)
    {
        db.Departments.Add(department);
        db.SaveChanges();

        return(RedirectToAction(nameof(Index)));
    }
Beispiel #7
0
        public ActionResult Add(Department department)
        {
            db.Departments.Add(department);
            db.SaveChanges();

            //var rowsAffected=db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #8
0
        public ActionResult Create([Bind(Include = "Id,Name")] Country country)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "Id,Name")] Test test)
        {
            if (ModelState.IsValid)
            {
                db.Tests.Add(test);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(test));
        }
Beispiel #10
0
        public ActionResult Create([Bind(Include = "Id,Name,CountryId")] State state)
        {
            if (ModelState.IsValid)
            {
                db.States.Add(state);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name", state.CountryId);
            return(View(state));
        }
Beispiel #11
0
 public bool AddEmployee(Employee employee)
 {
     try
     {
         db.Employees.Add(employee);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         //logger
         return(false);
     }
 }
        public Boolean AddEmployee(Emp emp)
        {
            try
            {
                _context.emps.Add(emp);
                _context.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #13
0
        public JsonResult DeleteData(int Id)
        {
            string retn = String.Empty;

            if (!String.IsNullOrEmpty(Id.ToString()))
            {
                using (EMSContext db = new EMSContext())
                {
                    try
                    {
                        var exist = db.ClassFormats.Where(e => e.Id == Id).FirstOrDefault();
                        if (exist != null)
                        {
                            db.ClassFormats.Remove(exist);
                            db.SaveChanges();
                            retn = "Success.";
                        }
                        else
                        {
                            retn = "Format ID is not found.";
                        }
                    }
                    catch
                    {
                        retn = "Failed";
                    }
                }
            }
            else
            {
                retn = "Failed";
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
        public JsonResult CreateData(Shift model)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    var exist = db.Shifts.Where(e => e.ShiftName == model.ShiftName && e.MediumId == model.MediumId && e.InstId == InstId).FirstOrDefault();
                    if (exist == null)
                    {
                        var advanced = new Shift();
                        advanced.ShiftName  = model.ShiftName;
                        advanced.InstId     = InstId;
                        advanced.MediumId   = model.MediumId;
                        advanced.ModifyId   = CurrentUserId;
                        advanced.ModifyTime = DateTime.Now;
                        db.Shifts.Add(advanced);
                        db.SaveChanges();
                        retn = "Success";
                    }
                    else
                    {
                        retn = "This Name is already exist.";
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #15
0
        public JsonResult DeleteData(int id)
        {
            string retn = String.Empty;

            if (!String.IsNullOrEmpty(id.ToString()))
            {
                using (EMSContext db = new EMSContext())
                {
                    try
                    {
                        var emp = db.Employees.Where(e => e.ID == id).FirstOrDefault();
                        if (emp != null)
                        {
                            db.Employees.Remove(emp);
                            db.SaveChanges();
                            retn = "Success.";
                        }
                        else
                        {
                            retn = "Employee ID is not found.";
                        }
                    }
                    catch
                    {
                        retn = "Failed";
                    }
                }
            }
            else
            {
                retn = "Failed";
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #16
0
        public IActionResult Index()
        {
            try
            {
                ViewBag.Active = "Kryefaqja";
                int nrPunetorve    = context.Employee.Count();
                int punetoretAktiv = context.Employee.Where(emp => emp.Status == true).Count();
                ViewData["nrPunetoreve"]   = nrPunetorve;
                ViewData["punetoretAktiv"] = punetoretAktiv;
                List <Attendance> attendance = context.Attendance.Where(a => a.StartTime.Date == DateTime.Now.Date).Include(a => a.Emp).ToList();
                ViewData["attendance"] = attendance;

                return(View());
            }
            catch (Exception e)
            {
                context.Logs.Add(new Logs
                {
                    mesazhi   = e.Message,
                    createdBy = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                    createdAt = DateTime.Now
                });
                context.SaveChanges();
                return(BadRequest(e));
            }
        }
Beispiel #17
0
        public JsonResult CreateData(ClassFormat model)
        {
            //var CurrentUserInstituteId = CommonFunction.CurrentUserInstituteId();
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    var exist = db.ClassFormats.Where(e => e.Name == model.Name).FirstOrDefault();
                    if (exist == null)
                    {
                        var advanced = new ClassFormat();
                        advanced.Name       = model.Name;
                        advanced.ModifyId   = CurrentUserId;
                        advanced.ModifyTime = DateTime.Now;
                        db.ClassFormats.Add(advanced);
                        db.SaveChanges();
                        retn = "Success";
                    }
                    else
                    {
                        retn = "This Name is already exist.";
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #18
0
        //[HttpPost]
        public JsonResult CreateData(Employee employee)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    var currentEmp = db.Employees.Where(e => e.Name == employee.Name).FirstOrDefault();
                    if (currentEmp == null)
                    {
                        db.Employees.Add(employee);
                        db.SaveChanges();
                        retn = "Success";
                    }
                    else
                    {
                        retn = "This Name is already exist.";
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #19
0
        public IActionResult Profile(int empId)
        {
            try
            {
                Employee employee = context.Employee.Find(empId);
                if (employee == null)
                {
                    //TODO return a view
                    return(NotFound());
                }
                return(View(employee));
            }
            catch (Exception e)
            {
                context.Logs.Add(new Logs
                {
                    mesazhi   = e.Message,
                    createdBy = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                    createdAt = DateTime.Now
                });

                context.SaveChanges();

                return(RedirectToAction("Error", "Home"));
            }
        }
Beispiel #20
0
        //[HttpPost]
        public JsonResult UpdateData(Medium model)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    if (model != null && model.Id > 0)
                    {
                        var exist = db.Mediums.Where(e => e.Id == model.Id).SingleOrDefault();
                        if (exist != null)
                        {
                            var duplicate = db.Mediums.Where(e => e.Id != model.Id && e.MediumName == model.MediumName && e.InstId == InstId).SingleOrDefault();
                            if (duplicate == null)
                            {
                                exist.Id         = model.Id;
                                exist.InstId     = InstId;
                                exist.MediumName = model.MediumName;
                                exist.ModifyId   = CurrentUserId;
                                exist.ModifyTime = DateTime.Now;
                                db.Mediums.Attach(exist);
                                db.Entry(exist).State = EntityState.Modified;
                                db.SaveChanges();
                                //if (selectedShifts != null)
                                //{
                                //    db.ShiftsMediums.RemoveRange(db.ShiftsMediums.Where(c => c.MediumId == model.Id));
                                //    foreach (string shiftId in selectedShifts)
                                //    {
                                //        var shiftMedium = new ShiftMedium();
                                //        shiftMedium.MediumId = model.Id;
                                //        shiftMedium.ShiftId = Convert.ToInt32(shiftId);
                                //        db.ShiftsMediums.Add(shiftMedium);
                                //    }
                                //    db.SaveChanges();
                                //}
                                retn = "Success.";
                            }
                            else
                            {
                                retn = "This Name Already Exist.";
                            }
                        }
                        else
                        {
                            retn = "Medium ID is not found.";
                        }
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #21
0
 public ActionResult <List <Employee> > Get()
 {
     try
     {
         List <Employee> employees = context.Employee.ToList();
         return(Ok(mapper.Map <List <EmployeeResponse> >(employees)));
     }
     catch (Exception e)
     {
         context.Logs.Add(new Logs {
             mesazhi = e.Message, createdBy = User.FindFirst(ClaimTypes.NameIdentifier).Value, createdAt = DateTime.Now
         });
         context.SaveChanges();
         return(BadRequest());
     }
 }
Beispiel #22
0
        //[HttpPost]
        public JsonResult UpdateData(Institute model)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    if (model != null && model.Id > 0)
                    {
                        var exist = db.Institutes.Where(e => e.Id == model.Id).SingleOrDefault();
                        if (exist != null)
                        {
                            var duplicate = db.Institutes.Where(e => e.Id != model.Id && e.ShortName == model.ShortName).FirstOrDefault();
                            if (duplicate == null)
                            {
                                exist.Id         = model.Id;
                                exist.Name       = model.Name;
                                exist.ShortName  = model.ShortName;
                                exist.Address    = model.Address;
                                exist.Email      = model.Email;
                                exist.Phone      = model.Phone;
                                exist.Mobile     = model.Mobile;
                                exist.Contact    = model.Contact;
                                exist.IsActive   = model.IsActive;
                                exist.JoinDate   = model.JoinDate;
                                exist.ExpireDate = model.ExpireDate;
                                exist.ModifyId   = CommonFunction.CurrentUserId();
                                exist.ModifyTime = DateTime.Now;
                                db.Institutes.Attach(exist);
                                db.Entry(exist).State = EntityState.Modified;
                                db.SaveChanges();
                                retn = "Success.";
                            }
                            else
                            {
                                retn = "This Short Name Already Exist.";
                            }
                        }
                        else
                        {
                            retn = "Institute Id is not found.";
                        }
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #23
0
        private void btn3_Click(object sender, EventArgs e)
        {
            Student std = new Student();

            std.Firstname  = txt3.Text;
            std.Surname    = txt4.Text;
            std.Department = combo.Text;


            EMSContext _db = new EMSContext();

            _db.Students.Add(std);
            _db.SaveChanges();
        }
Beispiel #24
0
        public JsonResult UpdateData(Shift model)
        {
            //var CurrentUserInstituteId = CommonFunction.CurrentUserInstituteId();
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    if (model != null && model.Id > 0)
                    {
                        var exist = db.Shifts.Where(e => e.Id == model.Id).SingleOrDefault();
                        if (exist != null)
                        {
                            var duplicate = db.Shifts.Where(e => e.Id != model.Id && e.ShiftName == model.ShiftName && e.MediumId == model.MediumId && e.InstId == InstId).SingleOrDefault();
                            if (duplicate == null)
                            {
                                exist.Id         = model.Id;
                                exist.InstId     = InstId;
                                exist.MediumId   = model.MediumId;
                                exist.ShiftName  = model.ShiftName;
                                exist.ModifyId   = CurrentUserId;
                                exist.ModifyTime = DateTime.Now;
                                db.Shifts.Attach(exist);
                                db.Entry(exist).State = EntityState.Modified;
                                db.SaveChanges();
                                retn = "Success.";
                            }
                            else
                            {
                                retn = "This Name Already Exist.";
                            }
                        }
                        else
                        {
                            retn = "Shift ID is not found.";
                        }
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #25
0
        //[HttpPost]
        public JsonResult CreateData(Medium model)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    var exist = db.Mediums.Where(e => e.MediumName == model.MediumName && e.InstId == InstId).FirstOrDefault();
                    if (exist == null)
                    {
                        var advanced = new Medium();
                        advanced.MediumName = model.MediumName;
                        advanced.InstId     = InstId;
                        advanced.ModifyId   = CurrentUserId;
                        advanced.ModifyTime = DateTime.Now;
                        db.Mediums.Add(advanced);
                        db.SaveChanges();
                        //if (selectedShifts != null)
                        //{
                        //    foreach (string shiftId in selectedShifts)
                        //    {
                        //        var shiftMedium = new ShiftMedium();
                        //        shiftMedium.MediumId = advanced.Id;
                        //        shiftMedium.ShiftId = Convert.ToInt32(shiftId);
                        //        db.ShiftsMediums.Add(shiftMedium);
                        //    }
                        //    db.SaveChanges();
                        //}

                        retn = "Success";
                    }
                    else
                    {
                        retn = "This Name is already exist.";
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #26
0
        public JsonResult UpdateData(Class model)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    if (model != null && model.Id > 0)
                    {
                        var exist = db.Classes.Where(e => e.Id == model.Id).SingleOrDefault();
                        if (exist != null)
                        {
                            var duplicate = db.Classes.Where(e => e.Id != model.Id && e.Name == model.Name && e.FormatId == model.FormatId).SingleOrDefault();
                            if (duplicate == null)
                            {
                                exist.Id         = model.Id;
                                exist.Name       = model.Name;
                                exist.FormatId   = model.FormatId;
                                exist.ModifyId   = CurrentUserId;
                                exist.ModifyTime = DateTime.Now;
                                db.Classes.Attach(exist);
                                db.Entry(exist).State = EntityState.Modified;
                                db.SaveChanges();
                                retn = "Success.";
                            }
                            else
                            {
                                retn = "This Name Already Exist.";
                            }
                        }
                        else
                        {
                            retn = "Class ID is not found.";
                        }
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #27
0
        private void btn7_Click(object sender, EventArgs e)
        {
            EMSContext  _db = new EMSContext();
            EmailDetail ed  = new EmailDetail();
            Student     std = new Student();
            User        use = new User();

            ed.Email    = txt6.Text;
            ed.Password = txt7.Text;
            //ed.StudentID = Convert.ToInt32(std.StudentID);
            //ed.StudentUserID = Convert.ToInt32(use.UserID);

            _db.EmailDetails.Add(ed);
            _db.SaveChanges();


            this.Close();
        }
Beispiel #28
0
        public IActionResult Regjistro(Employee employee)
        {
            try
            {
                logger.LogDebug("Regjistro()");
                if (ModelState.IsValid)
                {
                    employee.Status = true;

                    context.Entry(employee).Property("CreatedBy").IsModified   = false;
                    context.Entry(employee).Property("DateCreated").IsModified = false;

                    context.Employee.Add(employee);
                    context.SaveChanges();
                    logger.LogDebug("New Employee was created by " + User.Identity.Name);
                    TempData["registered"] = true;

                    context.Logs.Add(new Logs {
                        mesazhi   = $"Employee {employee.FirstName} {employee.LastName} was added with id: {employee.Id}",
                        createdBy = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                        createdAt = DateTime.Now
                    });
                    context.SaveChanges();

                    return(RedirectToAction("Allemployees"));
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                LogException(e);

                logger.LogError("Error creating new Employee", e);
                return(RedirectToAction("Error", "Home"));
            }
        }
Beispiel #29
0
        //[HttpPost]
        public JsonResult UpdateData(Employee employee)
        {
            string retn = String.Empty;

            using (EMSContext db = new EMSContext())
            {
                try
                {
                    if (employee != null && employee.ID > 0)
                    {
                        var CurrentEmployee = db.Employees.Where(e => e.ID == employee.ID).SingleOrDefault();
                        if (CurrentEmployee != null)
                        {
                            var UpdateEmployee = db.Employees.Where(e => e.ID != employee.ID && e.Name == employee.Name).SingleOrDefault();
                            if (UpdateEmployee == null)
                            {
                                CurrentEmployee.ID      = employee.ID;
                                CurrentEmployee.Name    = employee.Name;
                                CurrentEmployee.Address = employee.Address;
                                db.Employees.Attach(CurrentEmployee);
                                db.Entry(CurrentEmployee).State = EntityState.Modified;
                                db.SaveChanges();
                                retn = "Success.";
                            }
                            else
                            {
                                retn = "This Name Already Exist.";
                            }
                        }
                        else
                        {
                            retn = "Employee ID is not found.";
                        }
                    }
                }
                catch
                {
                    retn = "Failed";
                }
            }

            return(Json(retn, JsonRequestBehavior.AllowGet));
        }
Beispiel #30
0
        public JsonResult SaveFiles(UploadedFile model)
        {
            string Message, fileName, actualFileName;

            Message = fileName = actualFileName = string.Empty;
            bool flag = false;

            if (Request.Files != null)
            {
                var file = Request.Files[0];
                actualFileName = file.FileName;
                fileName       = Guid.NewGuid() + Path.GetExtension(file.FileName);
                int size = file.ContentLength;

                try
                {
                    file.SaveAs(Path.Combine(Server.MapPath("~/images/insts"), fileName));

                    UploadedFile f = new UploadedFile
                    {
                        FileName    = actualFileName,
                        FilePath    = fileName,
                        Description = model.Description,
                        FileSize    = size
                    };
                    using (EMSContext dc = new EMSContext())
                    {
                        dc.UploadedFiles.Add(f);
                        dc.SaveChanges();
                        Message = "File uploaded successfully";
                        flag    = true;
                    }
                }
                catch (Exception)
                {
                    Message = "File upload failed! Please try again";
                }
            }
            return(new JsonResult {
                Data = new { Message = Message, Status = flag }
            });
        }