public IHttpActionResult Post(Room value)
        {
            if (!dbContext.Room.Any(RoomName => RoomName.Name.Equals(value.Name)))
            {
                Room temp = new Room();
                temp.Name     = value.Name;
                temp.RoomId   = value.RoomId;
                temp.Location = value.Location;
                temp.Image    = value.Image;

                try
                {
                    dbContext.Add(temp);
                    dbContext.SaveChanges();
                    string message = "Registered";
                    return(Ok(message));
                }
                catch (Exception ex)
                {
                    string message = "Register Fail" + ex.Message;
                    return(Ok(message));
                }
            }
            else
            {
                string message = "Room name has been used";
                return(Ok(message));
            }
        }
 public IHttpActionResult Post(Testing value)
 {
     if (!dbContext.Testing.Any(User => User.Username.Equals(value.Username)))
     {
         Testing user = new Testing();
         user.Username = value.Username;
         user.Salt     = Convert.ToBase64String(Common.GetRandomSalt(16));
         user.Password = Convert.ToBase64String(Common.SaltHashPassword(
                                                    Encoding.ASCII.GetBytes(value.Password),
                                                    Convert.FromBase64String(user.Salt)));
         try
         {
             dbContext.Add(user);
             dbContext.SaveChanges();
             string message = "Registered liao";
             return(Ok(message));
         }
         catch (Exception ex)
         {
             string message = "Register failed " + ex.Message;
             return(Ok(message));
         }
     }
     else
     {
         string message = "Username has been used";
         return(Ok(message));
     }
 }
Exemple #3
0
        public IHttpActionResult Post(Users value)
        {
            var Id = int.Parse(dbContext.Users.Max(z => z.UsersId)) + 1;

            if (!dbContext.Users.Any(x => x.Email.Equals(value.Email)))
            {
                Users Nuser = new Users();
                Nuser.UsersId     = Id.ToString();
                Nuser.Names       = value.Names;
                Nuser.Passwords   = value.Passwords;
                Nuser.Email       = value.Email;
                Nuser.Department  = value.Department;
                Nuser.StartDate   = value.StartDate;
                Nuser.Nationality = value.Nationality;
                Nuser.Position    = value.Position;
                Nuser.Profilepic  = value.Profilepic;
                try
                {
                    dbContext.Add(Nuser);
                    dbContext.SaveChanges();
                    string message = "Registered";
                    var    example = new messageclass {
                        Message = message
                    };
                    return(Ok(example));
                }
                catch (Exception ex)
                {
                    string message = "Submit Failed" + ex.Message;
                    var    example = new messageclass {
                        Message = message
                    };
                    return(Ok(example));
                }
            }
            else
            {
                string message = "The Email has been used";
                var    example = new messageclass {
                    Message = message
                };
                return(Ok(example));
            }
        }
Exemple #4
0
        public IHttpActionResult Post(Cancellation value)
        {
            var Id = (dbContext.Cancellation.Max(z => z.CancellationId)) + 1;

            if (!dbContext.Cancellation.Any(cancel => cancel.BookingId.Equals(value.BookingId) && cancel.Status.Equals("New")))
            {
                Cancellation cancellation = new Cancellation();
                cancellation.CancellationId = Id;
                cancellation.BookingId      = value.BookingId;
                cancellation.Reason         = value.Reason;
                cancellation.Status         = "New";
                try
                {
                    dbContext.Add(cancellation);
                    dbContext.SaveChanges();
                    string message = "Submit Successfully";
                    var    example = new messageclass {
                        Message = message
                    };
                    return(Ok(example));
                }
                catch (Exception ex)
                {
                    string message = "Submit Failed" + ex.Message;
                    var    example = new messageclass {
                        Message = message
                    };
                    return(Ok(example));
                }
            }
            else
            {
                string message = "You have made a cancellation for this Booking already, please wait for the approval";
                var    example = new messageclass {
                    Message = message
                };
                return(Ok(example));
            }
        }
        public IHttpActionResult Post(Booking value)
        {
            if (!dbContext.Booking.Any(ID => ID.BookingId.Equals(value.BookingId)))
            {
                Booking temp = new Booking();
                temp.BookingId = value.BookingId;
                temp.UsersId   = value.UsersId;
                temp.RoomId    = value.RoomId;
                temp.Name      = value.Name;
                temp.Title     = value.Title;
                temp.Location  = value.Location;
                temp.Date      = value.Date;
                temp.Time      = value.Time;
                temp.Status    = "New";
                temp.StartTime = value.StartTime;
                temp.EndTime   = value.EndTime;

                try
                {
                    dbContext.Add(temp);
                    dbContext.SaveChanges();
                    string message = "Added";
                    return(Ok(message));
                }
                catch (Exception ex)
                {
                    string message = "Add Fail" + ex.Message;
                    return(Ok(message));
                }
            }
            else
            {
                string message = "Booking name has been used";
                return(Ok(message));
            }
        }