예제 #1
0
        /// <summary>
        /// GetRawMaterialListForPurchase method is used to view RawMaterials list in Purchase workflows
        /// </summary>
        /// <param name="optimized"></param>
        /// <param name="purchaseMatType"></param>
        /// <returns></returns>
        public List <RawMaterialObject> GetRawMaterialListForPurchase(int userId, string purchaseMatType = "")
        {
            List <RawMaterialObject> rawMaterialList = new List <RawMaterialObject>();

            var ress =
                from Mats in _db.MaterialDict
                join dslrs in _db.AspNetUserToDistiller on Mats.DistillerID equals dslrs.DistillerID into dslrs_join
                from dslrs in dslrs_join.DefaultIfEmpty()
                join MatsType in _db.MaterialType on Mats.MaterialDictID equals MatsType.MaterialDictID into MatsType_join
                from MatsType in MatsType_join.DefaultIfEmpty()
                join units in _db.UnitOfMeasurement on Mats.UnitOfMeasurementID equals units.UnitOfMeasurementID into units_join
                from units in units_join.DefaultIfEmpty()
                where
                MatsType.Name == purchaseMatType &&
                dslrs.UserId == userId
                select new
            {
                Mats.MaterialDictID,
                Mats.Name,
                Mats.UnitOfMeasurementID,
                Mats.Note,
                UnitName = units.Name
            };

            if (ress != null)
            {
                foreach (var i in ress)
                {
                    RawMaterialObject rObj = new RawMaterialObject();
                    rObj.RawMaterialId   = i.MaterialDictID;
                    rObj.RawMaterialName = i.Name;
                    rObj.Note            = i.Note;
                    rObj.UnitType        = i.UnitName;
                    rObj.UnitTypeId      = i.UnitOfMeasurementID;
                    rawMaterialList.Add(rObj);
                }
            }

            return(rawMaterialList);
        }
예제 #2
0
 public JsonResult UpdateRawMaterial(RawMaterialObject rawMaterialObject)
 {
     if (rawMaterialObject != null)
     {
         if (User.Identity.IsAuthenticated)
         {
             int userId = User.Identity.GetUserId <int>();
             if (userId > 0)
             {
                 bool returnResult = _dictionary.UpdateRawMaterial(userId, rawMaterialObject);
                 if (returnResult)
                 {
                     string message = "Raw Material dictionary record updated successfully.";
                     return(Json(message));
                 }
                 else
                 {
                     string message = "Failed to update Raw Material dictionary record!";
                     return(Json(message));
                 }
             }
             else
             {
                 return(Json("Unable to find UserId!"));
             }
         }
         else
         {
             return(Json("Unauthenticated user!"));
         }
     }
     else
     {
         return(Json("Back End received empty or undefined RawMaterial Object from the client"));
     }
 }
예제 #3
0
        /// <summary>
        /// GetRawMaterialListDict method that we use in dictionary workflows to view All Raw Materials record in Raw Material view workflow
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <RawMaterialObject> GetRawMaterialListDict(int userId)
        {
            List <RawMaterialObject> rawMaterialList = new List <RawMaterialObject>();
            var res =
                from matDict in _db.MaterialDict
                join unit in _db.UnitOfMeasurement on matDict.UnitOfMeasurementID equals unit.UnitOfMeasurementID into unit_join
                from unit in unit_join.DefaultIfEmpty()
                join us2Distills in _db.AspNetUserToDistiller on new { DistillerID = matDict.DistillerID } equals new { DistillerID = us2Distills.DistillerID } into us2Distills_join
            from us2Distills in us2Distills_join.DefaultIfEmpty()
            where
            us2Distills.UserId == userId
                select new
            {
                MaterialDictID      = (System.Int32?)matDict.MaterialDictID ?? (System.Int32?) 0,
                Name                = matDict.Name ?? string.Empty,
                UnitOfMeasurementID = (System.Int32?)matDict.UnitOfMeasurementID ?? (System.Int32?) 0,
                Note                = matDict.Note ?? string.Empty,
                UnitName            = unit.Name ?? string.Empty
            };

            if (res != null)
            {
                foreach (var i in res)
                {
                    RawMaterialObject rawMatObj = new RawMaterialObject();
                    rawMatObj.RawMaterialId   = (int)i.MaterialDictID;
                    rawMatObj.RawMaterialName = i.Name;
                    rawMatObj.Note            = i.Note;
                    rawMatObj.UnitType        = i.UnitName;
                    rawMatObj.UnitTypeId      = (int)i.UnitOfMeasurementID;
                    rawMaterialList.Add(rawMatObj);
                }
            }

            foreach (var iter in rawMaterialList)
            {
                var matTypes =
                    from mattype in _db.MaterialType
                    where mattype.MaterialDictID == iter.RawMaterialId
                    select mattype.Name;
                if (matTypes != null)
                {
                    PurchaseMaterialBooleanTypes types = new PurchaseMaterialBooleanTypes();
                    foreach (var it in matTypes)
                    {
                        if (it == "Fermentable")
                        {
                            types.Fermentable = true;
                        }
                        if (it == "Fermented")
                        {
                            types.Fermented = true;
                        }
                        if (it == "Distilled")
                        {
                            types.Distilled = true;
                        }
                        if (it == "Supply")
                        {
                            types.Supply = true;
                        }
                        if (it == "Additive")
                        {
                            types.Additive = true;
                        }
                    }
                    iter.PurchaseMaterialTypes = types;
                }
            }
            return(rawMaterialList);
        }
예제 #4
0
        /// <summary>
        /// UpdateRawMaterial method updates RawMaterial table
        /// <param name="rawMaterialObject"></param>
        /// <param name="userId"></param>
        /// <returns>bool</returns>
        public bool UpdateRawMaterial(int userId, RawMaterialObject rawMObject)
        {
            //define method execution return value to be false by default
            var retMthdExecResult = false;
            int materialDictID    = 0;
            int distillerId       = _dl.GetDistillerId(userId);

            if (rawMObject != null)
            {
                try
                {
                    materialDictID = rawMObject.RawMaterialId;

                    var ress =
                        (from rec in _db.MaterialDict
                         where rec.MaterialDictID == materialDictID && rec.DistillerID == distillerId
                         select rec).FirstOrDefault();

                    if (ress != null)
                    {
                        if (ress.Name != rawMObject.RawMaterialName)
                        {
                            ress.Name = rawMObject.RawMaterialName;
                        }

                        if (ress.Note != rawMObject.Note)
                        {
                            ress.Note = rawMObject.Note;
                        }

                        if (ress.UnitOfMeasurementID != rawMObject.UnitTypeId)
                        {
                            ress.UnitOfMeasurementID = rawMObject.UnitTypeId;
                        }
                    }
                    _db.SaveChanges();

                    // re-build relationships between given raw material and purchase material types
                    var res =
                        (from rec in _db.MaterialType
                         where rec.MaterialDictID == materialDictID
                         select rec);
                    if (res != null)
                    {
                        foreach (var i in res)
                        {
                            _db.MaterialType.Remove(i);
                        }
                        _db.SaveChanges();
                    }

                    if (rawMObject.PurchaseMaterialTypes.Additive)
                    {
                        try
                        {
                            MaterialType matType = new MaterialType();
                            matType.MaterialDictID = materialDictID;
                            matType.Name           = "Additive";
                            _db.MaterialType.Add(matType);
                            _db.SaveChanges();
                            retMthdExecResult = true;
                        }
                        catch
                        {
                            return(false);
                        }
                    }

                    if (rawMObject.PurchaseMaterialTypes.Distilled)
                    {
                        try
                        {
                            MaterialType matType = new MaterialType();
                            matType.MaterialDictID = materialDictID;
                            matType.Name           = "Distilled";
                            _db.MaterialType.Add(matType);
                            _db.SaveChanges();
                            retMthdExecResult = true;
                        }
                        catch
                        {
                            return(false);
                        }
                    }

                    if (rawMObject.PurchaseMaterialTypes.Fermentable)
                    {
                        try
                        {
                            MaterialType matType = new MaterialType();
                            matType.MaterialDictID = materialDictID;
                            matType.Name           = "Fermentable";
                            _db.MaterialType.Add(matType);
                            _db.SaveChanges();
                            retMthdExecResult = true;
                        }
                        catch
                        {
                            return(false);
                        }
                    }

                    if (rawMObject.PurchaseMaterialTypes.Fermented)
                    {
                        try
                        {
                            MaterialType matType = new MaterialType();
                            matType.MaterialDictID = materialDictID;
                            matType.Name           = "Fermented";
                            _db.MaterialType.Add(matType);
                            _db.SaveChanges();
                            retMthdExecResult = true;
                        }
                        catch
                        {
                            return(false);
                        }
                    }

                    if (rawMObject.PurchaseMaterialTypes.Supply)
                    {
                        try
                        {
                            MaterialType matType = new MaterialType();
                            matType.MaterialDictID = materialDictID;
                            matType.Name           = "Supply";
                            _db.MaterialType.Add(matType);
                            _db.SaveChanges();
                            retMthdExecResult = true;
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                    retMthdExecResult = true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Failed to Update Raw Material Record: " + e);
                    return(retMthdExecResult);
                }
            }

            return(retMthdExecResult);
        }
예제 #5
0
        /// <summary>
        /// CreateRawMaterial creates new record in Raw Materials table, inserts/updates Note table and inserts/updates
        /// </summary>
        /// <param name="rawMObject"></param>
        /// <param name="userId"></param>
        /// <returns>int</returns>
        public int CreateRawMaterial(int userId, RawMaterialObject rawMObject)
        {
            //define method execution return value to be false by default
            int retMthdExecResult = 0;
            int materialDictID    = 0;
            int distillerId       = _dl.GetDistillerId(userId);

            if (rawMObject != null)
            {
                try
                {
                    MaterialDict matDict = new MaterialDict();
                    matDict.Name = rawMObject.RawMaterialName;
                    matDict.UnitOfMeasurementID = rawMObject.UnitTypeId;
                    matDict.DistillerID         = distillerId;

                    if (rawMObject.Note != string.Empty && rawMObject.Note != null)
                    {
                        matDict.Note = rawMObject.Note;
                    }

                    _db.MaterialDict.Add(matDict);
                    _db.SaveChanges();

                    materialDictID = matDict.MaterialDictID;

                    // build relationships between given raw material and purchase material types
                    if (rawMObject.PurchaseMaterialTypes.Additive)
                    {
                        MaterialType matType = new MaterialType();
                        matType.MaterialDictID = materialDictID;
                        matType.Name           = "Additive";
                        _db.MaterialType.Add(matType);
                        _db.SaveChanges();
                    }

                    if (rawMObject.PurchaseMaterialTypes.Distilled)
                    {
                        MaterialType matType = new MaterialType();
                        matType.MaterialDictID = materialDictID;
                        matType.Name           = "Distilled";
                        _db.MaterialType.Add(matType);
                        _db.SaveChanges();
                    }

                    if (rawMObject.PurchaseMaterialTypes.Fermentable)
                    {
                        MaterialType matType = new MaterialType();
                        matType.MaterialDictID = materialDictID;
                        matType.Name           = "Fermentable";
                        _db.MaterialType.Add(matType);

                        MaterialDict2MaterialCategory md2mc = new MaterialDict2MaterialCategory();
                        md2mc.MaterialDictID = materialDictID;
                        md2mc.ProductionReportMaterialCategoryID = rawMObject.MaterialCategoryID;
                        _db.MaterialDict2MaterialCategory.Add(md2mc);
                        _db.SaveChanges();
                    }

                    if (rawMObject.PurchaseMaterialTypes.Fermented)
                    {
                        MaterialType matType = new MaterialType();
                        matType.MaterialDictID = materialDictID;
                        matType.Name           = "Fermented";
                        _db.MaterialType.Add(matType);

                        MaterialDict2MaterialCategory md2mc = new MaterialDict2MaterialCategory();
                        md2mc.MaterialDictID = materialDictID;
                        md2mc.ProductionReportMaterialCategoryID = rawMObject.MaterialCategoryID;
                        _db.MaterialDict2MaterialCategory.Add(md2mc);
                        _db.SaveChanges();
                    }

                    if (rawMObject.PurchaseMaterialTypes.Supply)
                    {
                        MaterialType matType = new MaterialType();
                        matType.MaterialDictID = materialDictID;
                        matType.Name           = "Supply";
                        _db.MaterialType.Add(matType);
                        _db.SaveChanges();
                    }

                    retMthdExecResult = materialDictID;
                }
                catch
                {
                    retMthdExecResult = 0;
                    throw;
                }
            }
            return(retMthdExecResult);
        }