コード例 #1
0
        /**
         **@ brief:  this method removes the data from bookibg table which becomes useless when the date passes
         **@ Params:  IJobExecutionContext context
         **/
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                DAO      dao         = new DAO();
                DateTime currentDate = DateTime.Now;
                currentDate = currentDate.AddDays(-3);
                string dateStr = currentDate.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
                dateStr = DateFormatter.removeTime(dateStr);
                dateStr = DateFormatter.setDateFormat(dateStr);
                DateTime dateValue = DateTime.ParseExact(dateStr, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

                List <BookingTable> listData = (from obj in dao.BookingTable_DBset
                                                where obj.bookingDate <= dateValue
                                                select obj).ToList();
                if (listData.Count >= 1)
                {
                    foreach (BookingTable item in listData)
                    {
                        dao.BookingTable_DBset.Remove(item);
                        dao.SaveChanges();
                    }
                }
            }

            catch (Exception ex)
            {
            }
        }
コード例 #2
0
        /**
         *@ brief:  this method first checks that parameters are not null or empty then it will check the parameter's character
         * length then it will get the user by name, phone and date. if it will get only one user then it will send that
         * user object in response, if it get more than one user then it will send the message "multipleUsers" wrapped in
         * http error response, if it does not finds any user then it will send the message "notFound" wrapped in
         * http error response
         *@ Params:  string fname, string lname, string phone, string joinDate
         *@ return:  HttpResponseMessage
         **/
        public HttpResponseMessage getUserByNamePhoneAndDateFromDB(string fname, string lname, string phone, string joinDate)
        {
            try
            {
                string[] inputStrings = trimInputString(fname, lname, phone, joinDate);
                fname    = inputStrings[0];
                lname    = inputStrings[1];
                phone    = inputStrings[2];
                joinDate = inputStrings[3];

                // checks string is null or empty
                if (!string.IsNullOrEmpty(fname) && !string.IsNullOrEmpty(lname) && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(joinDate))
                {
                    if (fname.Length <= 20 && lname.Length <= 20 && phone.Length <= 20 && joinDate.Length <= 50)
                    {
                        dao.Configuration.ProxyCreationEnabled = false;
                        dao.Configuration.LazyLoadingEnabled   = false;
                        joinDate = DateFormatter.setDateFormat(joinDate);
                        DateTime _joinDate = DateTime.ParseExact(joinDate, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);

                        var list = (from obj in dao.User_DBset
                                    where obj.firstName == fname && obj.lastName == lname &&
                                    obj.phoneNo == phone && obj.joinDate == _joinDate
                                    select obj).Include(c => c.club).ToList();

                        if (list.Count == 1)
                        {
                            var item = list.First();
                            response = Request.CreateResponse(HttpStatusCode.OK, item, GlobalConfiguration.Configuration);
                        }
                        if (list.Count > 1)
                        {
                            // make log that multiple user exist
                            response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "multipleUsers");
                        }
                        if (list.Count == 0)
                        {
                            response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "notFound");
                        }
                    }
                    else
                    {
                        response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "");
                    }
                }
                else
                {
                    //make log
                    response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "");
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "");
            }

            return(response);
        }
コード例 #3
0
        /**
         *@ brief:  this method first validate the parameters then it will add the user in database and return the User object
         * wrapped in response
         *@ Params:  int userTypeID, int clubID, string firstName, string lastName, string phoneNo,
         *  string joinDate
         *@ return:  HttpResponseMessage
         **/
        public HttpResponseMessage addUserInDB(int userTypeID, int clubID, string firstName, string lastName, string phoneNo,
                                               string joinDate)
        {
            try
            {
                string[] inputStrings = trimInputString(firstName, lastName, phoneNo, joinDate);
                firstName = inputStrings[0];
                lastName  = inputStrings[1];
                phoneNo   = inputStrings[2];
                joinDate  = inputStrings[3];

                if (validatingUserCredentials(userTypeID, clubID, firstName, lastName, phoneNo, joinDate))
                {
                    joinDate = DateFormatter.setDateFormat(joinDate);
                    DateTime _joinDate = DateTime.ParseExact(joinDate, "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
                    this.userTypeID = userTypeID;
                    this.clubID     = clubID;
                    this.firstName  = firstName.ToLower();
                    this.lastName   = lastName.ToLower();
                    this.phoneNo    = phoneNo;
                    this.isActive   = true;
                    this.isBanned   = false;
                    this.isApproved = true;
                    this.joinDate   = _joinDate;
                    dao.User_DBset.Add(this);
                    dao.SaveChanges();
                    dao.Configuration.ProxyCreationEnabled = false;
                    dao.Configuration.LazyLoadingEnabled   = false;
                    var item = (from obj in dao.User_DBset where obj.userID == this.userID select obj).Include(c => c.club).FirstOrDefault(); // FirstOrDefault() returns null if it couldnt find the element.  // First() throws exception when it couldnt find the element.
                    response = Request.CreateResponse(HttpStatusCode.OK, item, GlobalConfiguration.Configuration);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "");
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "");
            }
            return(response);
        }