Example #1
0
        public static Equipment NewEquipment(Equipment newEquipment)
        {
            if (Configuration.IsAStatus(newEquipment.Status) && EquipmentType.All.Any(et => et.ID == newEquipment.EquipmentTypeID))
            {
                BookITContext.Db.Equipments.Add(
                    new Equipment
                        {
                            ProductName = newEquipment.ProductName,
                            Status = newEquipment.Status,
                            EquipmentType = EquipmentType.All.FirstOrDefault(et => et.ID == newEquipment.EquipmentTypeID),
                            EquipmentTypeID = newEquipment.EquipmentTypeID
                        });
                BookITContext.Db.SaveChanges();
            }
            else
            {
                return null;
            }

            return
                All.FirstOrDefault(
                    e =>
                    e.EquipmentTypeID == newEquipment.EquipmentTypeID && e.ProductName.Equals(newEquipment.ProductName)
                    && e.Status.Equals(newEquipment.Status));
        }
Example #2
0
        public RequestStatus GetEquipment(ref Equipment equipment)
        {
            if (equipment == null)
            {
                return RequestStatus.InvalidInput;
            }

            equipment = Equipment.GetEquipmentByID(equipment.ID);
            return equipment != null ? RequestStatus.Success : RequestStatus.InvalidInput;
        }
Example #3
0
        public RequestStatus DeleteEquipment(string token, Equipment equipment)
        {
            if (string.IsNullOrWhiteSpace(token) || equipment == null || equipment.ID <= 0)
            {
                return RequestStatus.InvalidInput;
            }

            var p = Person.GetByToken(token);
            var eq = Equipment.GetEquipmentByID(equipment.ID);
            if (p == null || eq == null)
            {
                return RequestStatus.InvalidInput;
            }

            return p.IsAdmin() ? equipment.Remove() : RequestStatus.AccessDenied;
        }
Example #4
0
        public RequestStatus CreateNewEquipmentItem(string token, ref Equipment newEquipment)
        {
            if (string.IsNullOrWhiteSpace(token) || newEquipment == null || string.IsNullOrWhiteSpace(newEquipment.ProductName) || newEquipment.EquipmentTypeID <= 0)
            {
                return RequestStatus.InvalidInput;
            }

            var p = Person.GetByToken(token);
            if (p == null)
            {
                return RequestStatus.InvalidInput;
            }

            if (!p.IsAdmin())
            {
                return RequestStatus.AccessDenied;
            }

            newEquipment = Equipment.NewEquipment(newEquipment);
            return newEquipment != null ? RequestStatus.Success : RequestStatus.InvalidInput;
        }
Example #5
0
        public RequestStatus ChangeEquipmentItem(string token, ref Equipment equipment)
        {
            if (string.IsNullOrWhiteSpace(token) || equipment == null || equipment.ID <= 0)
            {
                return RequestStatus.InvalidInput;
            }

            var p = Person.GetByToken(token);
            var eq = Equipment.GetEquipmentByID(equipment.ID);
            if (p == null || eq == null)
            {
                return RequestStatus.InvalidInput;
            }

            if (!p.IsAdmin())
            {
                return RequestStatus.AccessDenied;
            }

            var rs = eq.Edit(equipment);
            equipment = eq;
            return rs;
        }
Example #6
0
        public RequestStatus Edit(Equipment updatedEquipment)
        {
            if (updatedEquipment == null)
            {
                return RequestStatus.InvalidInput;
            }

            this.EquipmentTypeID = updatedEquipment.EquipmentTypeID > 0
                                       ? updatedEquipment.EquipmentTypeID
                                       : this.EquipmentTypeID;
            this.ProductName = !string.IsNullOrWhiteSpace(updatedEquipment.ProductName)
                                   ? updatedEquipment.ProductName
                                   : this.ProductName;
            this.Status = Configuration.IsAStatus(updatedEquipment.Status)
                              ? updatedEquipment.Status
                              : this.Status;

            BookITContext.Db.SaveChanges();

            return RequestStatus.Success;
        }