示例#1
0
        // GET: Vacations/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Vacantion vacantion = await _context.Vacantions.Include(v => v.FromUser).FirstAsync(u => u.Id == id);

            if (vacantion == null)
            {
                return(NotFound());
            }
            VacationsDetailsViewModel model = new VacationsDetailsViewModel
            {
                Id               = vacantion.Id,
                FromDate         = vacantion.FromDate,
                ToDate           = vacantion.ToDate,
                Type             = vacantion.Type,
                DateOfCreation   = vacantion.DateOfCreation,
                HalfDayVacantion = vacantion.HalfDayVacantion,
                ImageUpload      = vacantion.ImageUpload,
                IsApproved       = vacantion.IsApproved,
                IsPending        = vacantion.IsPending,
                FromUser         = vacantion.FromUser
            };

            return(View(model));
        }
示例#2
0
        // GET: Vacations/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Vacantion vacantion = await _context.Vacantions.Include(v => v.FromUser).FirstAsync(u => u.Id == id);

            if (vacantion == null)
            {
                return(NotFound());
            }
            VacationsEditViewModel model = new VacationsEditViewModel
            {
                Id               = vacantion.Id,
                FromDate         = vacantion.FromDate,
                ToDate           = vacantion.ToDate,
                Type             = vacantion.Type,
                HalfDayVacantion = vacantion.HalfDayVacantion,
            };

            if (model.Type == "sick")
            {
                model.CurrentImage = vacantion.ImageUpload;

                /*var stream = new MemoryStream(model.CurrentImage);
                 * model.ImageUpload = new FormFile(stream, 0, model.CurrentImage.Length, "file", "sickSheet");*/
            }

            return(View(model));
        }
示例#3
0
        public string Reserv(int ID, int IDClient, int People)
        {
            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                string statement = "select * from `vacations` where `ID`=" + ID + " and`Disponibility` >=" + People + ";";

                MySqlCommand    cmd    = new MySqlCommand(statement, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    Vacantion vacantion = new Vacantion();
                    while (reader.Read())
                    {
                        vacantion.ID            = reader.GetInt32("ID");
                        vacantion.Days          = reader.GetInt32("Days");
                        vacantion.Schedule      = reader.GetDateTime("Schedule");
                        vacantion.Location      = reader.GetString("Location");
                        vacantion.Disponibility = reader.GetInt32("Disponibility");

                        vacantion.Disponibility -= People;
                        vacantion.IDClient       = IDClient;
                        updateVacantion(vacantion);
                        vacantion.Disponibility = People;
                        addBookedVacantion(vacantion);
                        return("Succes!");
                    }
                }
            }
            return("Error!");
        }
示例#4
0
        private void btnDeleteVacantion_Click(object sender, EventArgs e)
        {
            try
            {
                Vacantion vacantion = new Vacantion();
                vacantion.ID = Convert.ToInt32(txtVacId.Text);

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:58069/");

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.PostAsJsonAsync("api/deleteVacantion", vacantion).Result;

                if (response.IsSuccessStatusCode)
                {
                    MessageBox.Show("Operation succeded");
                }
                else
                {
                    MessageBox.Show("Operation failed");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        public IList <Vacantion> getBookedVacantions()
        {
            IList <Vacantion> VacantionList = new List <Vacantion>();

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                string statement = "SELECT * FROM bookedVacations";

                MySqlCommand    cmd    = new MySqlCommand(statement, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Vacantion vacantion = new Vacantion();
                        vacantion.ID            = reader.GetInt32("ID");
                        vacantion.IDClient      = reader.GetInt32("IDClient");
                        vacantion.Days          = reader.GetInt32("Days");
                        vacantion.Schedule      = reader.GetDateTime("Schedule");
                        vacantion.Location      = reader.GetString("Location");
                        vacantion.Disponibility = reader.GetInt32("Disponibility");
                        VacantionList.Add(vacantion);
                    }
                }
            }
            return(VacantionList);
        }
示例#6
0
        public async Task <IActionResult> Edit(string id, [Bind("VacantionId,VacantionType,VacantionDays,ConsumedDays,DaysLeft")] Vacantion vacantion)
        {
            if (id != vacantion.VacantionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vacantion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VacantionExists(vacantion.VacantionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacantion));
        }
示例#7
0
        // POST: Vacations/Delete/5
        public async Task <IActionResult> Delete(int id)
        {
            Vacantion vacation = await _context.Vacantions.FirstAsync(u => u.Id == id);

            _context.Remove(vacation);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
示例#8
0
        public async Task <IActionResult> Reject(int id)
        {
            Vacantion vacation = await _context.Vacantions.FirstAsync(u => u.Id == id);

            vacation.IsApproved = false;
            vacation.IsPending  = false;
            _context.SaveChanges();
            return(RedirectToAction(nameof(ApproveRequests)));
        }
示例#9
0
        public async Task <IActionResult> SendRequest(VacationsCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                User currentUser = await GetCurrentUser();

                Vacantion newVacation = new Vacantion
                {
                    FromDate         = model.FromDate,
                    ToDate           = model.ToDate,
                    Type             = model.Type,
                    FromUser         = currentUser,
                    HalfDayVacantion = model.HalfDayVacantion
                };

                bool mark = false;
                if (model.FromDate > model.ToDate)
                {
                    ModelState.AddModelError("FromDate", "From Date must be less than To Date.");
                    ModelState.AddModelError("ToDate", "From Date must be less than To Date.");
                    mark = true;
                }

                if (model.Type == "sick" && model.ImageUpload == null)
                {
                    ModelState.AddModelError("ImageUpload", "Must upload image of sheet or record.");
                    mark = true;
                }
                else if (model.ImageUpload != null)
                {
                    if (model.ImageUpload.Length > 0)
                    //Convert Image to byte and save to database
                    {
                        byte[] p1 = null;
                        using (var fs1 = model.ImageUpload.OpenReadStream())
                            using (var ms1 = new MemoryStream())
                            {
                                fs1.CopyTo(ms1);
                                p1 = ms1.ToArray();
                            }
                        newVacation.ImageUpload = p1;
                    }
                }

                if (mark)
                {
                    return(View(model));
                }

                _context.Add(newVacation);
                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("VacantionId,VacantionType,VacantionDays,ConsumedDays,DaysLeft")] Vacantion vacantion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vacantion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacantion));
        }
示例#11
0
        public async Task <IActionResult> Edit(VacationsEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Vacantion vacation = await _context.Vacantions.Include(v => v.FromUser).FirstAsync(u => u.Id == model.Id);

                vacation.Id               = model.Id;
                vacation.FromDate         = model.FromDate;
                vacation.ToDate           = model.ToDate;
                vacation.Type             = model.Type;
                vacation.HalfDayVacantion = model.HalfDayVacantion;
                vacation.DateOfCreation   = DateTime.Now;
                vacation.Editted          = true;

                if (vacation.Type == "sick")
                {
                    vacation.HalfDayVacantion = false;
                    vacation.ImageUpload      = model.CurrentImage;

                    if (model.CurrentImage == null && model.ImageUpload == null)
                    {
                        ModelState.AddModelError("ImageUpload", "Must upload image of sheet or record.");
                        return(await Edit(model.Id));
                    }
                    else if (model.ImageUpload != null)
                    {
                        if (model.ImageUpload.Length > 0)
                        //Convert Image to byte and save to database
                        {
                            byte[] p1 = null;
                            using (var fs1 = model.ImageUpload.OpenReadStream())
                                using (var ms1 = new MemoryStream())
                                {
                                    fs1.CopyTo(ms1);
                                    p1 = ms1.ToArray();
                                }
                            vacation.ImageUpload = p1;
                        }
                    }
                }
                else
                {
                    vacation.ImageUpload = null;
                }


                _context.Update(vacation);
                _context.SaveChanges();

                return(RedirectToAction("Details", "Vacations", new { id = vacation.Id }));
            }

            return(View(model));
        }
示例#12
0
        public void deleteVacantion(Vacantion vacantion)
        {
            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "DELETE FROM vacations WHERE ID = @id";
                cmd.Prepare();

                cmd.Parameters.AddWithValue("@id", vacantion.ID);
                cmd.ExecuteNonQuery();
            }
        }
示例#13
0
 public void addVacantion(Vacantion vacantion)
 {
     using (MySqlConnection conn = new MySqlConnection(connString))
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection  = conn;
         cmd.CommandText = "INSERT INTO vacations(Days,Schedule,Location,Disponibility) VALUES(@Days,@Schedule,@Location,@Disponibility)";
         cmd.Prepare();
         cmd.Parameters.AddWithValue("@Days", vacantion.Days);
         cmd.Parameters.AddWithValue("@Schedule", vacantion.Schedule);
         cmd.Parameters.AddWithValue("@Location", vacantion.Location);
         cmd.Parameters.AddWithValue("@Disponibility", vacantion.Disponibility);
         cmd.ExecuteNonQuery();
     }
 }
示例#14
0
        public void updateVacantion(Vacantion vacantion)
        {
            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "UPDATE vacations SET Days=@Days, Schedule=@Schedule, Location=@Location, Disponibility=@Disponibility WHERE ID = @ID";
                cmd.Prepare();

                cmd.Parameters.AddWithValue("@ID", vacantion.ID);
                cmd.Parameters.AddWithValue("@Days", vacantion.Days);
                cmd.Parameters.AddWithValue("@Schedule", vacantion.Schedule);
                cmd.Parameters.AddWithValue("@Location", vacantion.Location);
                cmd.Parameters.AddWithValue("@Disponibility", vacantion.Disponibility);
                cmd.ExecuteNonQuery();
            }
        }
示例#15
0
        public void deleteVacantion([FromBody] Vacantion vacantion)
        {
            DataProvide up = new DataProvide();

            up.deleteVacantion(vacantion);
        }
示例#16
0
        public void addVacantion([FromBody] Vacantion vacantion)
        {
            DataProvide dp = new DataProvide();

            dp.addVacantion(vacantion);
        }
示例#17
0
 public void CreateVacantion(Vacantion vacantion)
 {
     repositoryWrapper.Vacantion.Create(vacantion);
     repositoryWrapper.Save();
 }
示例#18
0
 public void EditVacantion(Vacantion vacantion)
 {
     repositoryWrapper.Vacantion.Update(vacantion);
     repositoryWrapper.Save();
 }
示例#19
0
 public void DeleteVacantion(Vacantion vacantion)
 {
     repositoryWrapper.Vacantion.Delete(vacantion);
     repositoryWrapper.Save();
 }