예제 #1
0
        private void editcreatebtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(roomnametxtbox.Text) || string.IsNullOrEmpty(roompricetxtbox.Text) || string.IsNullOrEmpty(bedsnumbertxtbox.Text))
            {
                MessageBox.Show("Fill all fields", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                Room room = new Room()
                {
                    RoomNo            = roomnametxtbox.Text,
                    RoomPrice         = Convert.ToDecimal(roompricetxtbox.Text),
                    NumberOfBeds      = Convert.ToInt32(bedsnumbertxtbox.Text),
                    Discount          = string.IsNullOrEmpty(discounttxtbox.Text) ? 0 : Convert.ToInt32(discounttxtbox.Text),
                    NumberOfChildBeds = string.IsNullOrEmpty(childbedstxtbox.Text) ? 0 : Convert.ToInt32(childbedstxtbox.Text),
                    FloorNumber       = Convert.ToInt32(floornumbertxtbox.Text),
                    RoomTypesId       = (int)roomtype.SelectedValue,
                    RoomStatusId      = (int)roomstatus.SelectedValue
                };
                if (isEdit)
                {
                    if (newimg)
                    {
                        JsonResponseModel imgresponse = fileRepo.EditImage(roommainimg.ImageLocation, img);
                        if (!string.IsNullOrEmpty(imgresponse.obj.ToString()))
                        {
                            room.Img = imgresponse.obj.ToString();
                        }
                    }
                    room.Id = roomId;
                    roomRepository.EditRoom(room);
                    MessageBox.Show("Room Edited", "Edited", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (newimg)
                    {
                        JsonResponseModel imgresponse = fileRepo.UploadImage(roommainimg.ImageLocation);
                        if (!string.IsNullOrEmpty(imgresponse.obj.ToString()))
                        {
                            room.Img = imgresponse.obj.ToString();
                        }
                    }

                    roomRepository.AddRoom(room);
                    MessageBox.Show("Room Created", "Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                roomdatagrid.DataSource = roomRepository.GetAllRooms();
                roommainimg.Image       = null;
                clearbtn_Click_1(sender, e);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }