Ejemplo n.º 1
0
 public IActionResult Post([FromBody] Contact contact)
 {
     if (contact.Id == 0)
     {
         db.Contact.Add(contact);
         db.Addresses.AddRange(contact.Addresses);
     }
     else
     {
         var exContact       = db.Contact.Where(x => x.Id == contact.Id).SingleOrDefault();
         var existAddressess = db.Addresses.Where(x => x.ContactId == contact.Id).ToList();
         exContact.FirstName = contact.FirstName;
         exContact.LastName  = contact.LastName;
         exContact.NickName  = contact.NickName;
         exContact.DOB       = contact.DOB;
         var newAddressess = contact.Addresses.Where(x => x.Id == 0).ToList();
         db.Addresses.AddRange(newAddressess);
         foreach (var exAddresses in existAddressess)
         {
             if (!contact.Addresses.Any(x => x.Id == exAddresses.Id))
             {
                 db.Addresses.Remove(exAddresses);
             }
         }
     }
     db.SaveChanges();
     return(Ok(contact.Id));
 }
Ejemplo n.º 2
0
        public IHttpActionResult PutDEPARTMENTS(int id, DEPARTMENTS dEPARTMENTS)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dEPARTMENTS.DEPARTMENT_ID)
            {
                return(BadRequest());
            }

            db.Entry(dEPARTMENTS).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DEPARTMENTSExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutEMPLOYEES(int id, EMPLOYEES eMPLOYEES)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eMPLOYEES.MANAGER_ID)
            {
                return(BadRequest());
            }

            db.Entry(eMPLOYEES).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EMPLOYEESExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IActionResult Create([Bind("CompanyName,CompanyDesc,CompanyCity,CompanyCountry,CompanyPhone,CompanyEmail,CompanyWebSite")] Company company)
        {
            var newcompany = _compctx.Companies.Add(company);

            _compctx.SaveChanges();
            return(Ok(company));
        }
        public IActionResult Add(Employee model)
        {
            db.Employees.Add(model);
            db.SaveChanges();

            return(Redirect("/home/index"));
        }
        public bool AddNewVacation(VacationInsertAndUpdate vacation)
        {
            var totalDays             = (vacation.EndDate - vacation.StartDate).TotalDays;
            var updateVacationBalence = (from u in context.Users
                                         where vacation.EmployeeID == u.UserID
                                         select u).Single();

            if (vacation.Type == Types.Annual)
            {
                updateVacationBalence.AnnualVacationBalance = updateVacationBalence.AnnualVacationBalance - Math.Round(totalDays);
            }
            if (CheckBalence(updateVacationBalence.AnnualVacationBalance))
            {
                context.Vacations.Add(new Vacation()
                {
                    Type        = vacation.Type,
                    Status      = vacation.Status,
                    Attatchment = vacation.Attatchment,
                    Description = vacation.Description,
                    StartDate   = vacation.StartDate,
                    EndDate     = vacation.EndDate,
                    EmployeeID  = vacation.EmployeeID,
                });

                context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public IHttpActionResult EditBetaMember(int id, BetaListDto betaListDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var bTeam = context.BetaLists.SingleOrDefault(c => c.Id == id);

            if (bTeam == null)
            {
                return(NotFound());
            }

            bTeam.InitialStatus   = betaListDto.InitialStatus;
            bTeam.HRScreening     = betaListDto.HRScreening;
            bTeam.DeptAssessment  = betaListDto.DeptAssessment;
            bTeam.Examination     = betaListDto.Examination;
            bTeam.InitStatRemarks = betaListDto.InitStatRemarks;
            bTeam.HrRemarks       = betaListDto.HrRemarks;
            bTeam.ExamRemarks     = betaListDto.ExamRemarks;
            bTeam.DeptRemarks     = betaListDto.DeptRemarks;
            context.SaveChanges();

            return(Ok());
        }
        public static void Task2(HRContext ctx)
        {
            Console.Out.Write("Stock name: ");
            String stockName = Console.ReadLine();

            Console.Out.Write("DateTime (YYYY-MM-DD): ");
            DateTime.TryParse(Console.ReadLine(), out DateTime tempDate);

            Console.Out.Write("Price: ");
            Decimal.TryParse(Console.ReadLine(), out Decimal price);

            Console.Out.Write("Number of Shares: ");
            int.TryParse(Console.ReadLine(), out int shares);

            Console.Out.WriteLine("Choose one:");
            Console.Out.WriteLine("1. Existing trader");
            Console.Out.WriteLine("2. New trader");
            String newOrExisting = Console.ReadLine();

            if (newOrExisting.Equals("1"))
            {
                Console.Out.Write("Link trade to trader with which ID? ");
                long.TryParse(Console.ReadLine(), out long traderID);
                Person person1 = ctx.Persons.Where(p => p.PersonId == traderID).FirstOrDefault();
                //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDat e, purchasePrice = price, shares = shares, Trade2Id = traderID };
                //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDate, purchasePrice = price, shares = shares, trader = person1 };
                Trade2 trade = new Trade2(stockName, tempDate, price, shares, person1);
                ctx.Trades.Add(trade);
                ctx.SaveChanges();
                Console.WriteLine("Trade saved.");
            }
            else if (newOrExisting.Equals("2"))
            {
                Console.Out.Write("Trader first name: ");
                String traderFirstName = Console.ReadLine();

                Console.Out.Write("Trader last name: ");
                String traderLastName = Console.ReadLine();

                Console.Out.Write("Trader phone: ");
                String phone   = Console.ReadLine();
                Person person2 = new Person()
                {
                    firstname = traderFirstName, lastname = traderLastName, phone = phone
                };
                //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDate, purchasePrice = price, shares = shares, trader = person2 };
                Trade2 trade = new Trade2(stockName, tempDate, price, shares, person2);
                ctx.Trades.Add(trade);
                ctx.Persons.Add(person2);
                ctx.SaveChanges();
                Console.WriteLine("Trade and person saved.");
            }
            else
            {
                Console.Out.WriteLine("Invalid option. Try again");
            }
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "ID,Name")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ID,Name")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
Ejemplo n.º 11
0
        public ActionResult Userinfo([Bind(Include = "Id,Name,Phone,Email,Gender")] info info)
        {
            if (ModelState.IsValid)
            {
                db.infos.Add(info);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(info));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
Ejemplo n.º 13
0
        public ActionResult Create([Bind(Include = "ID,Name")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Include = "Id,Name,Address,DepartmentId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", employee.DepartmentId);
            return(View(employee));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,CityID")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityID = new SelectList(db.Cities, "ID", "Name", user.CityID);
            return(View(user));
        }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Include = "EmployeeId,FirstName,MiddleName,LastName,DOB,Position,DepartmentId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employee.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Department, "DepartmentId", "DepartmentName", employee.DepartmentId);
            return(View(employee));
        }
Ejemplo n.º 17
0
        public ActionResult Create([Bind(Include = "ID,ChildRoleID,ParentRoleID")] RoleHierarchy roleHierarchy)
        {
            if (ModelState.IsValid)
            {
                db.RoleHierarchies.Add(roleHierarchy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ChildRoleID  = new SelectList(db.Roles, "ID", "Name", roleHierarchy.ChildRoleID);
            ViewBag.ParentRoleID = new SelectList(db.Roles, "ID", "Name", roleHierarchy.ParentRoleID);
            return(View(roleHierarchy));
        }
Ejemplo n.º 18
0
 public IActionResult Post([FromBody] Tag tag)
 {
     if (!string.IsNullOrEmpty(tag.Value))
     {
         var checkValue = tag.Value.ToLower();
         if (!db.Tag.Any(x => x.Value.ToLower() == tag.Value))
         {
             db.Tag.Add(tag);
             db.SaveChanges();
         }
     }
     return(Ok());
 }
Ejemplo n.º 19
0
        public IActionResult Post([FromBody] Contact contact)
        {
            if (contact.Id == 0)
            {
                db.Contact.Add(contact);
                db.Email.AddRange(contact.Email);
                db.Phone.AddRange(contact.Phone);
            }
            else
            {
                var exContact   = db.Contact.Where(x => x.Id == contact.Id).SingleOrDefault();
                var existEmails = db.Email.Where(x => x.ContactId == contact.Id).ToList();
                var existPhones = db.Phone.Where(x => x.ContactId == contact.Id).ToList();
                exContact.FirstName = contact.FirstName;
                exContact.LastName  = contact.LastName;
                exContact.City      = contact.City;
                exContact.Street    = contact.Street;
                var newEmails = contact.Email.Where(x => x.Id == 0).ToList();
                var newPhones = contact.Phone.Where(x => x.Id == 0).ToList();
                db.Email.AddRange(newEmails);
                db.Phone.AddRange(newPhones);
                foreach (var exPhone in existPhones)
                {
                    if (!contact.Phone.Any(x => x.Id == exPhone.Id))
                    {
                        db.Phone.Remove(exPhone);
                    }
                }
                foreach (var exEmail in existEmails)
                {
                    if (!contact.Email.Any(x => x.Id == exEmail.Id))
                    {
                        db.Email.Remove(exEmail);
                    }
                }
            }
            var contacTags = contact.ContactTag;

            foreach (var cTag in contacTags)
            {
                if (!db.ContactTag.Any(x => x.ContactId == contact.Id && x.TagId == cTag.TagId))
                {
                    db.ContactTag.Add(cTag);
                    db.SaveChanges();
                }
            }
            db.SaveChanges();
            return(Ok(contact.Id));
        }
Ejemplo n.º 20
0
        public IActionResult CreateRegUser([FromBody] User user)
        {
            if (user == null)
            {
                return(BadRequest());
            }
            _ctx.Add(user);
            _ctx.SaveChanges();

            return(Created("api/user", user));
        }
Ejemplo n.º 21
0
        public ActionResult Create([Bind(Include = "ID,UserID,BossEmployeeID,RoleID,ProjectID,SalaryAmount")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BossEmployeeID = new SelectList(db.Employees, "ID", "ID", employee.BossEmployeeID);
            ViewBag.ProjectID      = new SelectList(db.Projects, "ID", "Name", employee.ProjectID);
            ViewBag.RoleID         = new SelectList(db.Roles, "ID", "Name", employee.RoleID);
            ViewBag.UserID         = new SelectList(db.Users, "ID", "FirstName", employee.UserID);
            return(View(employee));
        }
Ejemplo n.º 22
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified, ActivationCode")] Users users)
        {
            bool   status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                #region Check for Email Validation
                var isExist = DoesEmailExist(users.Email);
                if (isExist == true)
                {
                    // Throw error in the textbox on View()
                    ModelState.AddModelError("EmailExist", "This E-mail already exists in the System.");
                    return(View(users));
                }
                #endregion

                #region Generate Activation Code
                users.ActivationCode = Guid.NewGuid();
                #endregion

                #region Password Hashing
                users.Password        = Crypto.Hash(users.Password);
                users.ConfirmPassword = Crypto.Hash(users.ConfirmPassword);
                #endregion

                users.IsEmailVerified = false;

                #region Save Data to Database
                context.UsersDbSet.Add(users);
                context.SaveChanges();
                //Send Email to User
                SendVerificationLinkEmail(users.Email, users.ActivationCode.ToString());
                message = "Just a few more steps, registration was a success. An account activation link" +
                          " has been sent to your E-mail account: " + users.Email + ", please open your e-mail for the activation.";
                status = true;
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = status;
            return(View(users));
        }
 public void Update(Department item)
 {
     if (item != null)
     {
         db.SaveChanges();
     }
 }
 public void Update(Position item)
 {
     if (item != null)
     {
         db.SaveChanges();
     }
 }
Ejemplo n.º 25
0
        public IActionResult EditUser([FromBody] RegUser regUser, string userName)
        {
            if (regUser == null)
            {
                return(BadRequest());
            }

            var todo = _ctx.RegUsers.FirstOrDefault(u => u.UserName == userName);

            if (todo == null)
            {
                return(NotFound());
            }
            if (User.Identity.IsAuthenticated)
            {
                todo.UserName        = regUser.UserName;
                todo.RegUserName     = regUser.RegUserName;
                todo.RegUserSex      = regUser.RegUserSex;
                todo.RegUserDoB      = regUser.RegUserDoB;
                todo.RegUserLastName = regUser.RegUserLastName;
                todo.RegUserCity     = regUser.RegUserCity;
                todo.RegUserCountry  = regUser.RegUserCountry;
                todo.LocationChange  = regUser.LocationChange;
                todo.RegUserPartFull = regUser.RegUserPartFull;
                todo.RegUserKeyword  = regUser.RegUserKeyword;
                todo.StatusOfUser    = regUser.StatusOfUser;
            }
            _ctx.SaveChanges();

            return(Ok("Edited"));
        }
 public void Update(Employee item)
 {
     if (item != null)
     {
         db.SaveChanges();
     }
 }
Ejemplo n.º 27
0
        public int Salary_standardUpdate(Salary_standardModel ssm)
        {
            Salary_standard ss = new Salary_standard()
            {
                ssd_id        = ssm.ssd_id,
                standard_id   = ssm.standard_id,
                standard_name = ssm.standard_name,
                designer      = ssm.designer,
                register      = ssm.register,
                checker       = ssm.checker,
                changer       = ssm.changer,
                regist_time   = ssm.regist_time,
                check_time    = ssm.check_time,
                change_time   = ssm.change_time,
                salary_sum    = ssm.salary_sum,
                check_status  = ssm.check_status,
                change_status = ssm.change_status,
                check_comment = ssm.check_comment,
                remark        = ssm.remark,
            };

            hr.Salary_standard.Attach(ss);
            hr.Entry(ss).State = System.Data.Entity.EntityState.Modified;
            return(hr.SaveChanges());
        }
Ejemplo n.º 28
0
 public void Update(Project item)
 {
     if (item != null)
     {
         db.SaveChanges();
     }
 }
 // Task 3: Delete all traders and trades
 public static void Task3(HRContext ctx)
 {
     Console.WriteLine("Transaction started");
     ctx.Persons.RemoveRange(ctx.Persons);
     ctx.Trades.RemoveRange(ctx.Trades);
     Console.WriteLine("All trades and traders deleted from the database.");
     ctx.SaveChanges();
 }
Ejemplo n.º 30
0
        public void CreateNewUser(UserInsertAndUpdate user)
        {
            context.Users.Add(new User()
            {
                Name      = user.Name,
                LastName  = user.LastName,
                Username  = user.Username,
                Email     = user.Email,
                Password  = user.Password.GetHashCode().ToString(),
                Mobile    = user.Mobile,
                JobTitle  = user.JobTitle,
                ManagerID = user.ManagerID,
                // alter later so we can add manger
                Role = Roles.Employee
            });

            context.SaveChanges();
        }
Ejemplo n.º 31
0
        public void test_connection_ef()
        {
            Console.WriteLine(TimeZoneInfo.Local.Id);

            Database.SetInitializer(new DropCreateDatabaseAlways<HRContext>());

            using (var hr_context = new HRContext())
            //using(var tran = hr_context.Database.BeginTransaction())
            {
                //hr_context.Database.CreateIfNotExists();
                //var dhing = (from x in hr_context.Players
                //             where x.Name == "Dhing"
                //             select x).FirstOrDefault();

                //dhing.CreatedDate = DateTime.Now;
                var p = new Player()
                {
                    Id= 3,
                    Name = "Dhing",
                    CreatedDate = DateTime.Now
                };

                hr_context.Players.Add(p);
                hr_context.SaveChanges();
                //tran.Commit();
            }
        }