예제 #1
0
        public ReturnValueRepo Create(int parentId, string name)
        {
            var result = new ReturnValueRepo();
            var cat    = InventoryDatabase.item_subtype.FirstOrDefault(s => s.subtype_name.Equals(name));

            if (cat == null)
            {
                var newItemSubtype = new item_subtype {
                    subtype_parent_id = parentId, subtype_name = name
                };

                InventoryDatabase.item_subtype.Add(newItemSubtype);
                if (InventoryDatabase.SaveChanges() > 0)
                {
                    result.Param1  = newItemSubtype.subtype_id.ToString();
                    result.Success = true;
                }
                else
                {
                    result.Message = "Error creating subtype!";
                }
            }
            else
            {
                result.Message = "Subtype already exist!";
            }
            return(result);
        }
예제 #2
0
        public ReturnValueRepo Create(string name)
        {
            var result = new ReturnValueRepo();
            var cat    = InventoryDatabase.item_type.FirstOrDefault(s => s.item_type_name.Equals(name));

            if (cat == null)
            {
                var newCat = new item_type()
                {
                    item_type_name = name
                };
                InventoryDatabase.item_type.Add(newCat);
                if (InventoryDatabase.SaveChanges() > 0)
                {
                    result.Success = true;
                    result.Param1  = newCat.item_type_id.ToString();
                }
            }
            else
            {
                result.Message = "Type already exist!";
            }

            return(result);
        }
        public bool InsertTransmittal(TransmittalViewModel newTrans)
        {
            var trans = new transmital {
                approved_by_id = newTrans.ApprovedById,
                approved_date  = newTrans.ApprovedDate,
                created_date   = newTrans.CreatedDate,
                prepared_by_id = newTrans.PreparedById,
                noted_by_id    = newTrans.NotedById,

                transmitted_date             = newTrans.TransmittedDate,
                transmitted_to_company_id    = newTrans.TransmittedToCompanyId,
                transmitted_to_department_id = newTrans.TransmittedToDepartmentId,
                transmitted_to_user_id       = newTrans.TransmittedToUserId
            };

            InventoryDatabase.transmitals.Add(trans);
            var result = InventoryDatabase.SaveChanges();

            if (result > 0)
            {
                foreach (TransmittalItemViewModel itm in newTrans.TransmittalItems)
                {
                    InventoryDatabase.transmittal_items.Add(new transmittal_items
                    {
                        item_id        = itm.ItemId,
                        item_quantity  = itm.Quantity,
                        transmittal_id = trans.transmital_id,
                    });
                    InventoryDatabase.SaveChanges();
                }
                return(true);
            }

            return(false);
        }
예제 #4
0
        public int CreateNewUser(string username, string password, int type, string firstname, string lastname, int departmentId, bool isMale = true, bool isDisabled = false)
        {
            var newUser = new user
            {
                user_username   = username,
                user_password   = password,
                user_type       = type,
                user_first_name = firstname,
                user_last_name  = lastname,
                user_department = departmentId,
                is_male         = isMale,
                is_disabled     = isDisabled
            };

            InventoryDatabase.users.Add(newUser);
            try
            {
                InventoryDatabase.SaveChanges();
                return(newUser.user_id);
            }
            catch
            {
                return(0);
            }
        }
예제 #5
0
        public int Update(int id, string name)
        {
            var cat = InventoryDatabase.item_type.FirstOrDefault(s => s.item_type_id == id);

            if (cat != null)
            {
                var catExist = InventoryDatabase.item_type.FirstOrDefault(s => s.item_type_name == name);


                //Name already exist
                if (catExist != null)
                {
                    if (catExist.item_type_id == id)
                    {
                        return(-1);
                    }
                    return(-2);
                }

                cat.item_type_name = name;
            }

            InventoryDatabase.SaveChanges();
            return(1);
        }
 public bool InsertNewAttachment(int itemId, byte[] bArr, string filename)
 {
     InventoryDatabase.item_image.Add(new item_image
     {
         item_image_parent  = itemId,
         item_image_picture = bArr,
         type     = (int)AttachmentType.Document,
         filename = filename
     });
     InventoryDatabase.SaveChanges();
     return(true);
 }
        public bool DeleteAttachment(int attachmentId)
        {
            var file = InventoryDatabase.item_image.FirstOrDefault(h => h.item_image_id == attachmentId);

            if (file != null)
            {
                InventoryDatabase.item_image.Remove(file);
                InventoryDatabase.SaveChanges();
                return(true);
            }
            return(false);
        }
        public int Insert(ItemViewModel newItem, int userId)
        {
            var itm = new item
            {
                item_name        = newItem.Name,
                item_brand_id    = newItem.BrandId,
                item_description = newItem.Description,
                item_subtype_id  = (int)newItem.SubTypeId,
                item_type_id     = (int)newItem.TypeId,

                item_last_updated_user = newItem.LastUpdatedUserId,
                item_lifespan          = newItem.LifeSpan,
                item_model             = newItem.Model,
                item_purchase_date     = newItem.PurchaseDate,
                item_purchase_price    = newItem.PurchasePrice,
                item_current_value     = newItem.Currentvalue,
                item_salvage_value     = newItem.SalvageValue,
                item_serial            = newItem.Serial,

                item_asset_tag    = newItem.AssetTag,
                item_os_id        = (int)newItem.OS,
                item_processor_id = (int)newItem.Processor,
                item_memory_id    = (int)newItem.Memory,
                item_hdd1_id      = (int)newItem.HDD1,
                item_hdd2_id      = (int)newItem.HDD2,
                item_login_type   = (int)newItem.LoginType,
                purchase_order_no = newItem.PurchaseOrderNo,
                sales_invoice_no  = newItem.SalesInvoiceNo,

                item_status        = (int)newItem.Status,
                item_last_updated  = DateTime.Now,
                item_current_owner = newItem.CurrentOwner,
            };

            if (itm.item_current_owner > 0)
            {
                itm.item_borrow_date     = DateTime.Now;
                itm.item_expected_return = DateTime.Now.AddYears(5);
            }

            InventoryDatabase.items.Add(itm);

            try
            {
                InventoryDatabase.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(itm.item_id);
        }
예제 #9
0
        public int Delete(int id)
        {
            var cat = InventoryDatabase.item_type.FirstOrDefault(s => s.item_type_id == id);

            if (cat != null)
            {
                InventoryDatabase.item_type.Remove(cat);
            }

            InventoryDatabase.SaveChanges();
            return(1);
        }
        public bool AttachAssetTag(int itemId, string assetTag)
        {
            var item = InventoryDatabase.items.FirstOrDefault(h => h.item_id == itemId);

            if (item != null)
            {
                item.item_asset_tag = assetTag;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public int CreateDepartment(string name)
        {
            var d = new department {
                department_name = name, department_company_id = 0
            };

            InventoryDatabase.departments.Add(d);

            if (InventoryDatabase.SaveChanges() > 0)
            {
                return(d.department_id);
            }
            return(0);
        }
        public bool UpdateOwnerByStatus(int id, int owner)
        {
            var item = InventoryDatabase.items.FirstOrDefault(x => x.item_id == id);

            if (item != null)
            {
                item.item_current_owner = owner;

                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public bool UpdateItemStatusToBroken(int subtypeId, int reqby, ItemStatus status)
        {
            var item = InventoryDatabase.items.FirstOrDefault(x => x.item_subtype_id == subtypeId && x.item_status == 1 && x.item_current_owner == reqby);

            if (item != null)
            {
                item.item_status        = (int)ItemStatus.Broken;
                item.item_current_owner = reqby;
                item.item_last_updated  = DateTime.Now;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
예제 #14
0
        public bool InsertTransaction(int systemUserIdm, int otherUserId, int transactionType, string remarks, int itemId = 0)
        {
            InventoryDatabase.transacitons.Add(new transaciton {
                transaction_other_user_id  = otherUserId,
                transaction_remarks        = remarks,
                transaction_system_user_id = systemUserIdm,
                transaction_date           = DateTime.Now,
                transaction_type_id        = (int)transactionType,
                transaction_item_id        = itemId,
                transaction_request_id     = 0
            });

            var result = InventoryDatabase.SaveChanges();

            return(result > 0);
        }
        public bool UpdateRequest(RequestViewModel req)
        {
            var oldRequest = InventoryDatabase.requests.FirstOrDefault(x => x.request_id == req.Id);

            if (oldRequest != null)
            {
                oldRequest.request_process_by_id = req.ProcessedById;
                oldRequest.request_process_date  = req.ProcessDate;
                oldRequest.request_status        = (int)req.RequestedStatus;
                oldRequest.request_remarks       = req.AdminRemarks;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public int CreateOS(int id, string name)
        {
            var newOs = new operation_system()
            {
                os_id = id, os_name = name
            };

            InventoryDatabase.operation_system.Add(newOs);
            if (InventoryDatabase.SaveChanges() > 0)
            {
                return(newOs.os_id);
            }


            return(-1);
        }
        public bool UpdateItemStatusById(int id, ItemStatus status, int curowner)
        {
            var item = InventoryDatabase.items.FirstOrDefault(x => x.item_id == id);

            if (item != null)
            {
                item.item_status        = (int)status;
                item.item_last_updated  = DateTime.Now;
                item.item_current_owner = curowner;

                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public bool UpdateRequestStatus(int id, string remark, int user, RequestStatus status, int itemId = 0)
        {
            var oldRequest = InventoryDatabase.requests.FirstOrDefault(x => x.request_id == id);

            if (oldRequest != null)
            {
                oldRequest.request_status        = (int)status;
                oldRequest.request_process_date  = DateTime.Now;
                oldRequest.request_process_by_id = user;
                oldRequest.request_admin_remarks = remark;
                oldRequest.request_item_id       = itemId;

                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public bool Update(ItemViewModel newItem, int userId)
        {
            var item = InventoryDatabase.items.FirstOrDefault(h => h.item_id == newItem.Id);

            if (item != null)
            {
                item.item_name              = newItem.Name;
                item.item_brand_id          = newItem.BrandId;
                item.item_description       = newItem.Description;
                item.item_subtype_id        = (int)newItem.SubTypeId;
                item.item_type_id           = (int)newItem.TypeId;
                item.item_last_updated      = newItem.LastUpdatedDate;
                item.item_last_updated_user = newItem.LastUpdatedUserId;
                item.item_lifespan          = newItem.LifeSpan;
                item.item_model             = newItem.Model;
                item.item_purchase_date     = newItem.PurchaseDate;
                item.item_purchase_price    = newItem.PurchasePrice;
                item.sales_invoice_no       = newItem.SalesInvoiceNo;
                item.purchase_order_no      = newItem.PurchaseOrderNo;

                item.item_current_value = newItem.Currentvalue;
                item.item_salvage_value = newItem.SalvageValue;
                //item.item_current_owner = newItem.CurrentOwner;
                item.item_serial         = newItem.Serial;
                item.item_status         = (int)newItem.Status;
                item.item_os_id          = (int)newItem.OS;
                item.item_processor_id   = (int)newItem.Processor;
                item.item_memory_id      = (int)newItem.Memory;
                item.item_hdd1_id        = (int)newItem.HDD1;
                item.item_hdd2_id        = (int)newItem.HDD2;
                item.item_salvage_value  = newItem.SalvageValue;
                item.item_login_type     = (int)newItem.LoginType;
                item.item_printer_type   = (int)newItem.PrinterType;
                item.item_ip_address     = newItem.NetworkIP;
                item.item_ip_subnet_mask = newItem.NetworkSubnet;
                item.item_ip_gateway     = newItem.NetworkGateway;

                InventoryDatabase.SaveChanges();

                return(true);
            }

            return(false);
        }
        public bool UpdateItemStatus(int itemId, int userId, int itemStatus, DateTime expectedReturn)
        {
            //var item = InventoryDatabase.Items.FirstOrDefault(h => h.id == itemId);
            var item = InventoryDatabase.items.FirstOrDefault(x => x.item_id == itemId);

            if (item != null)
            {
                item.item_status            = itemStatus;
                item.item_current_owner     = userId;
                item.item_last_updated      = DateTime.Now;
                item.item_last_updated_user = userId;
                item.item_expected_return   = expectedReturn;
                item.item_borrow_date       = DateTime.Now;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            return(false);
        }
        public int InsertNewRequest(RequestViewModel req)
        {
            //request.RequestedDate = DateTime.Now;
            //request.RequestType = (RequestType)cbxRequestType.SelectedItem;
            //request.RequestedStatus = RequestStatus.New;
            //request.RequestItemType = (PrimaryItemType)cbxType.SelectedItem;
            //request.RequestSecondaryItemType = (SecondaryItemType)cbxSubType.SelectedItem;
            //request.NeededDate = dtpNeededDate.Value;
            //request.UserId = (int)cbxUsers.SelectedValue;
            //request.Remarks = txtRemarks.ToString();


            var newReq = new request
            {
                request_date                 = req.RequestedDate,
                request_requested_by_id      = req.RequestedById,
                request_item_primary_type    = (int)req.RequestItemPrimaryType,
                request_item_secondary_type  = (int)req.RequestSecondaryItemType,
                request_subtype              = req.Subtype,
                request_status               = (int)req.RequestedStatus,
                request_user_id              = req.UserId,
                request_type                 = (int)req.RequestType,
                request_need_date            = req.NeededDate,
                request_expected_return_date = req.ExpectedReturnDate,
                request_remarks              = req.Remarks,
                request_admin_remarks        = req.AdminRemarks
            };

            InventoryDatabase.requests.Add(newReq);
            if (InventoryDatabase.SaveChanges() > 0)
            {
                return(newReq.request_id);
            }
            else
            {
                return(0);
            }
        }
예제 #22
0
        public ReturnValueRepo DeleteSubType(int id)
        {
            var result  = new ReturnValueRepo();
            var subType = InventoryDatabase.item_subtype.FirstOrDefault(h => h.subtype_id == id);

            if (subType != null)
            {
                InventoryDatabase.item_subtype.Remove(subType);
                try
                {
                    InventoryDatabase.SaveChanges();
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.Message = ex.Message;
                    result.Param1  = ex.InnerException != null ? ex.InnerException.Message : "";
                }
            }

            return(result);
        }
예제 #23
0
        public bool UpdateItemTypeImage(int typeId, byte[] bArr)
        {
            //var item = InventoryDatabase.Items.FirstOrDefault(h => h.id == itemId);
            var item = InventoryDatabase.item_subtype_image.FirstOrDefault(x => x.subtype_image_subtype_id == typeId);

            if (item != null)
            {
                item.subtype_image_picture = bArr;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            else
            {
                InventoryDatabase.item_subtype_image.Add(new item_subtype_image
                {
                    subtype_image_subtype_id = typeId,
                    subtype_image_picture    = bArr
                });
                InventoryDatabase.SaveChanges();
                return(true);
            }
        }
예제 #24
0
        public bool UpdateUser(int userId, string firstName, string lastName, int departmentId, int userType = 3, string password = "", bool disabled = false)
        {
            var user = InventoryDatabase.users.FirstOrDefault(h => h.user_id == userId);

            if (user != null)
            {
                user.user_first_name = firstName;
                user.user_last_name  = lastName;

                user.user_department = departmentId;
                user.user_type       = userType;
                user.is_disabled     = disabled;
                if (password != "")
                {
                    user.user_password = password;
                }

                InventoryDatabase.SaveChanges();

                return(true);
            }

            return(false);
        }
        public int UpdateBrand(int id, string name)
        {
            var brand = InventoryDatabase.brands.FirstOrDefault(b => b.brand_parent_id == id);

            if (brand != null)
            {
                var brandExists = InventoryDatabase.brands.FirstOrDefault(b => b.brand_name == name);


                //Name already exist
                if (brandExists != null)
                {
                    if (brandExists.brand_id == id)
                    {
                        return(-1);
                    }
                    return(-2);
                }

                brand.brand_name = name;
            }
            InventoryDatabase.SaveChanges();
            return(1);
        }
        public int UpdateOS(int id, string name)
        {
            var os = InventoryDatabase.operation_system.FirstOrDefault(b => b.os_id == id);

            if (os != null)
            {
                var osExists = InventoryDatabase.operation_system.FirstOrDefault(b => b.os_name == name);


                //Name already exist
                if (osExists != null)
                {
                    if (osExists.os_id == id)
                    {
                        return(-1);
                    }
                    return(-2);
                }

                os.os_name = name;
            }
            InventoryDatabase.SaveChanges();
            return(1);
        }
        public bool UpdateItemImage(int itemId, byte[] bArr)
        {
            //var item = InventoryDatabase.Items.FirstOrDefault(h => h.id == itemId);
            var item = InventoryDatabase.item_image.FirstOrDefault(x => x.item_image_parent == itemId && x.type == (int)AttachmentType.Image);

            if (item != null)
            {
                item.item_image_picture = bArr;
                InventoryDatabase.SaveChanges();

                return(true);
            }
            else
            {
                InventoryDatabase.item_image.Add(new item_image
                {
                    item_image_parent  = itemId,
                    item_image_picture = bArr,
                    type = (int)AttachmentType.Image
                });
                InventoryDatabase.SaveChanges();
                return(true);
            }
        }