Ejemplo n.º 1
0
        /// <summary>
        /// Ställa sig i kö för en bokning
        /// </summary>
        /// <param name="residentId"></param>
        /// <param name="reservationsId"></param>
        /// <returns></returns>
        public static MethodResult MakeQueReservation(int residentId, string reservationsId, byte[] rowversion)
        {
            var result = new MethodResult();
            using (var db = new WasherContext())
            {
                var x = db.Reservation.FirstOrDefault(r => r.Id == reservationsId);
                if (x == null) return result;

                if (!x.Reservationlist.Any())
                {
                    result.Succes = false;
                    result.Message = "Du kan inte ställa dig i kö på en bokning som inte är bokad";
                    return result;

                }

                var residentToAdd = db.Residents.FirstOrDefault(a => a.ResidentId == residentId);

                x.Reservationlist.Add(residentToAdd);
                db.Entry(x).OriginalValues["RowVersion"] = rowversion;
                db.Entry(x).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    result.Succes = false;
                    result.Message = ex.Message;
                    return result;

                }

                return result;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Skapar en bokning
        /// För att ställa sig i kö behövs det läggas till mer kod     
        /// </summary>
        /// <param name="residentId"></param>
        /// <param name="reservationsId"></param>
        /// <returns></returns>
        public static MethodResult MakeReservation(int residentId, string reservationsId, byte[] rowversion)
        {
            var result = new MethodResult();
            using (var db = new WasherContext())
            {
                var x = db.Reservation.FirstOrDefault(r => r.Id == reservationsId);
                if (x != null)
                {

                    if (x.ResidentId != 0)
                    {
                        return result;

                    }

                    x.ResidentId = residentId;
                    x.RowVersion = rowversion;
                    var residentToAdd = db.Residents.FirstOrDefault(a => a.ResidentId == residentId);

                    var existingreservations = residentToAdd?.Reservations
                        .Where(r => r.StarTime > DateTime.Now);

                    //if (existingreservations?.Count() > 2)
                    //{

                    //    return result;
                    //}
                    x.Reservationlist.Add(residentToAdd);
                    db.Entry(x).OriginalValues["RowVersion"] = rowversion;
                    db.Entry(x).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {

                        result.ConcurrEx = true;
                        result.Message = "Någon annan han före! Looser!";
                        return result;
                    }
                    result.Succes = true;
                    return result;
                }
                result.Succes = true;
                return result;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Felanmäla ett maskin
        /// </summary>
        /// <param name="residentId">Ange ResidentID</param>
        /// <param name="errorDescription">Skriv en beskrivning av felet</param>
        /// <param name="machineId">Ange Machine ID</param>
        /// <returns>Returnera</returns>
        public static MethodResult CreateErrorMessage(int residentId, string errorDescription, int machineId)
        {
            var mr = new MethodResult();
            var em = new ErrorMessage();

            using (var db = new WasherContext())
            {
                em.ErrorDescription = errorDescription;
                em.ResidentId = residentId;
                em.Machine_Id = machineId;
                em.Time = DateTime.Now;

                db.ErrorMessages.Add(em);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {

                    throw;
                }
            }
            mr.Object = em;
            mr.Succes = true;
            return mr;
        }