示例#1
0
        public ServiceResult InsertMaterialWithdraw(Material_Withdraw pWith)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    pWith.Create_On = currentdate;
                    pWith.Create_By = userlogin.Email_Address;
                    pWith.Update_On = currentdate;
                    pWith.Update_By = userlogin.Email_Address;
                    pWith.PLC       = userlogin.Profile_ID;

                    db.Material_Withdraw.Add(pWith);
                    SaveProductMaping(db, pWith.Product_Code, pWith.Product_Name);
                    db.SaveChanges();
                    db.Entry(pWith).GetDatabaseValues();
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                        Field = Resource.Material_Withdraw
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_INSERT,
                    Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
                    Field = Resource.Material_Withdraw,
                    Exception = ex
                });
            }
        }
        public ServiceResult UpdateGlobalLookupData(Global_Lookup_Data pData)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Global_Lookup_Data.Where(w => w.Lookup_Data_ID == pData.Lookup_Data_ID).FirstOrDefault();
                    if (current != null)
                    {
                        db.Entry(current).CurrentValues.SetValues(pData);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Global_Lookup
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Global_Lookup,
                    Exception = ex
                });
            }
        }
示例#3
0
        public ServiceResult UpdateMaterialWithdraw(Material_Withdraw pWith)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Material_Withdraw.Where(w => w.Withdraw_ID == pWith.Withdraw_ID).FirstOrDefault();
                    if (current != null)
                    {
                        pWith.Update_On = currentdate;
                        pWith.Update_By = userlogin.Email_Address;
                        SaveProductMaping(db, pWith.Product_Code, pWith.Product_Name);
                        db.Entry(current).CurrentValues.SetValues(pWith);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Material_Withdraw
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Material_Withdraw,
                    Exception = ex
                });
            }
        }
示例#4
0
 public ServiceResult InsertPageRole(Page_Role pPR)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             db.Page_Role.Add(pPR);
             db.SaveChanges();
             db.Entry(pPR).GetDatabaseValues();
             return(new ServiceResult()
             {
                 Code = ReturnCode.SUCCESS,
                 Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                 Field = Resource.Page_Role
             });
         }
     }
     catch (Exception ex)
     {
         return(new ServiceResult()
         {
             Code = ReturnCode.ERROR_INSERT,
             Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
             Field = Resource.Page_Role,
             Exception = ex
         });
     }
 }
示例#5
0
 public int DeleteAttachment(Nullable <System.Guid> pAttachmentID)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             var attach = db.Raw_Material_Attachment.Where(w => w.Attachment_ID == pAttachmentID).FirstOrDefault();
             if (attach == null)
             {
                 return(-500);
             }
             else
             {
                 attach.Record_Status   = Record_Status.Delete;
                 attach.Update_On       = currentdate;
                 attach.Update_By       = userlogin.Email_Address;
                 db.Entry(attach).State = EntityState.Modified;
                 //db.Raw_Material_Attachment.Remove(attach);
                 db.SaveChanges();
                 return(1);
             }
         }
     }
     catch
     {
         //Log
         return(-500);
     }
 }
示例#6
0
        public ServiceResult UpdatePageRole(Page_Role pPR)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Page_Role.Where(w => w.Page_Role_ID == pPR.Page_Role_ID).FirstOrDefault();
                    if (current != null)
                    {
                        db.Entry(current).CurrentValues.SetValues(pPR);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Page_Role
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Page_Role,
                    Exception = ex
                });
            }
        }
示例#7
0
 public ServiceResult InsertMaterialRejectForm(Material_Reject_Form pForm)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             db.Material_Reject_Form.Add(pForm);
             db.SaveChanges();
             db.Entry(pForm).GetDatabaseValues();
             return(new ServiceResult()
             {
                 Code = ReturnCode.SUCCESS,
                 Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                 Field = Resource.Material_Reject
             });
         }
     }
     catch (Exception ex)
     {
         return(new ServiceResult()
         {
             Code = ReturnCode.ERROR_INSERT,
             Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
             Field = Resource.Material_Reject,
             Exception = ex
         });
     }
 }
示例#8
0
        public ServiceResult ResetPassword(int uID, String PWD)
        {
            using (var db = new AgnosDBContext())
            {
                try
                {
                    var user = getUser(uID);
                    user.PWD = hashSHA256(PWD);

                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS),
                        Field = Resource.Reset_Password
                    });
                }
                catch (Exception ex)
                {
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.ERROR_SAVE,
                        Msg = Error.GetMessage(ReturnCode.ERROR_SAVE),
                        Field = Resource.Reset_Password,
                        Exception = ex
                    });
                }
            }
        }
示例#9
0
        public ServiceResult SaveMaterialRejectForm(Material_Reject_Form pForm)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var form = db.Material_Reject_Form.Where(w => w.Material_Reject_ID == pForm.Material_Reject_ID).FirstOrDefault();
                    if (form != null)
                    {
                        db.Material_Reject_Form.Remove(form);
                    }

                    db.Material_Reject_Form.Add(pForm);
                    db.SaveChanges();
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                        Field = Resource.Material_Reject
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_INSERT,
                    Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
                    Field = Resource.Attachment_File,
                    Exception = ex
                });
            }
        }
示例#10
0
 public ServiceResult InsertGlobalLookupData(Global_Lookup_Data pData)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             db.Global_Lookup_Data.Add(pData);
             db.SaveChanges();
             db.Entry(pData).GetDatabaseValues();
             return(new ServiceResult()
             {
                 Code = ReturnCode.SUCCESS,
                 Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                 Field = Resource.Global_Lookup
             });
         }
     }
     catch (Exception ex)
     {
         return(new ServiceResult()
         {
             Code = ReturnCode.ERROR_INSERT,
             Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
             Field = Resource.Global_Lookup,
             Exception = ex
         });
     }
 }
示例#11
0
 public ServiceResult InsertRawMaterial(Raw_Material pRaw)
 {
     try
     {
         using (var db = new AgnosDBContext())
         {
             SaveProductMaping(db, pRaw.Product_Code, pRaw.Product_Name);
             pRaw.Create_By = userlogin.Email_Address;
             pRaw.Create_On = currentdate;
             pRaw.Update_By = userlogin.Email_Address;
             pRaw.Update_On = currentdate;
             pRaw.Record_By = userlogin.Profile_ID;
             db.Raw_Material.Add(pRaw);
             db.SaveChanges();
             db.Entry(pRaw).GetDatabaseValues();
             return(new ServiceResult()
             {
                 Code = ReturnCode.SUCCESS,
                 Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                 Field = Resource.Income_Raw_Material
             });
         }
     }
     catch (Exception ex)
     {
         return(new ServiceResult()
         {
             Code = ReturnCode.ERROR_INSERT,
             Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
             Field = Resource.Income_Raw_Material,
             Exception = ex
         });
     }
 }
示例#12
0
        public ServiceResult InsertUser(User_Profile pProfile)
        {
            try
            {
                var currentdate = StoredProcedure.GetCurrentDate();
                using (var db = new AgnosDBContext())
                {
                    if (db.Users.Where(w => w.UserName.Equals(pProfile.Email_Address.ToLower())).FirstOrDefault() != null)
                    {
                        return new ServiceResult {
                                   Code = ReturnCode.ERROR_DATA_DUPLICATE, Msg = "duplicate " + "Email", Field = "Employee"
                        }
                    }
                    ;

                    var guid = Guid.NewGuid().ToString();
                    while (db.Users.Where(w => w.Id == guid).FirstOrDefault() != null)
                    {
                        guid = Guid.NewGuid().ToString();
                    }

                    db.Users.Add(new ApplicationUser()
                    {
                        Id = guid, UserName = pProfile.Email_Address.ToLower()
                    });

                    pProfile.PWD = hashSHA256(pProfile.PWD);
                    pProfile.ApplicationUser_Id = guid;
                    pProfile.Create_By          = userlogin.Email_Address;
                    pProfile.Create_On          = currentdate;
                    pProfile.Update_By          = userlogin.Email_Address;
                    pProfile.Update_On          = currentdate;

                    db.User_Profile.Add(pProfile);
                    db.SaveChanges();
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                        Field = Resource.User
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_INSERT,
                    Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
                    Field = Resource.User,
                    Exception = ex
                });
            }
        }
示例#13
0
        public void SetExpireActivationLinkTimeLimit(int link_id)
        {
            DateTime currentdate = StoredProcedure.GetCurrentDate();

            using (var db = new AgnosDBContext())
            {
                Activation_Link link = db.Activation_Link
                                       .Where(w => w.Activation_ID == link_id)
                                       .FirstOrDefault();

                link.Time_Limit      = currentdate;
                db.Entry(link).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
示例#14
0
        public int sendResetPassword(int Profile_ID, string domain)
        {
            DateTime currentdate = StoredProcedure.GetCurrentDate();

            using (var db = new AgnosDBContext())
            {
                try
                {
                    User_Profile user = getUser(Profile_ID);
                    //GENERATE ACTIVATION CODE
                    String code;
                    do
                    {
                        code = "R" + randomString(40);
                    } while (!validateActivationCode(code));

                    Activation_Link activation_link = new Activation_Link()
                    {
                        Activation_Code = code,
                        //SET Time_Limit to activate within LINK_TIME_LIMIT hour
                        Time_Limit = currentdate.AddHours(LINK_TIME_LIMIT),
                        Profile_ID = user.Profile_ID
                    };

                    db.Activation_Link.Add(activation_link);
                    db.SaveChanges();
                    try
                    {
                        //SEND EMAIL
                        //4		System	Send reset password link to user
                        EmailTemplete.sendResetPasswordEmail(user.Email_Address, code, user.Name, domain);
                    }
                    catch
                    {
                        return(0);
                    }
                }
                catch
                {
                    return(0);
                }
            }

            return(1);
        }
示例#15
0
        public ServiceResult InsertRawMaterialAttachment(ref Nullable <Guid> pAttID, Nullable <int> pRawID, byte[] file, string filename, string field)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    pAttID = Guid.NewGuid();
                    //Insert
                    var att = new Raw_Material_Attachment();

                    att.Attachment_ID        = pAttID.Value;
                    att.Attachment_File      = file;
                    att.Raw_Material_ID      = pRawID;
                    att.Attachment_File_Name = filename;
                    att.Attachment_Field     = field;

                    att.Create_On = currentdate;
                    att.Create_By = userlogin.Email_Address;
                    att.Update_On = currentdate;
                    att.Update_By = userlogin.Email_Address;
                    db.Raw_Material_Attachment.Add(att);
                    db.SaveChanges();
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_INSERT),
                        Field = "File"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_INSERT,
                    Msg = Error.GetMessage(ReturnCode.ERROR_INSERT),
                    Field = "File",
                    Exception = ex
                });
            }
        }
示例#16
0
        public Boolean UpdateLastConnection(int Profile_ID)
        {
            try
            {
                DateTime currentdate = StoredProcedure.GetCurrentDate();
                using (var db = new AgnosDBContext())
                {
                    User_Profile user = getUser(Profile_ID);
                    user.Latest_Connection = currentdate;
                    user.Update_By         = userlogin.Email_Address;
                    db.Entry(user).State   = EntityState.Modified;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch
            {
                //Log
                return(false);
            }
        }
示例#17
0
        public Boolean UpdateLoginAttempt(String email)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    User_Profile user = db.User_Profile.Where(i => i.Email_Address.Equals(email.ToLower())).FirstOrDefault();
                    if (user != null)
                    {
                        user.Login_Attempt   = user.Login_Attempt.HasValue ? user.Login_Attempt.Value : 0 + 1;
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    return(true);
                }
            }
            catch
            {
                //Log
                return(false);
            }
        }
示例#18
0
        public ServiceResult UpdateRawMaterialAttachment(Nullable <Guid> pAttID, byte[] file, string filename)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var att = db.Raw_Material_Attachment.Where(w => w.Attachment_ID == pAttID).FirstOrDefault();
                    if (att != null)
                    {
                        //UPDATE
                        att.Attachment_File      = file;
                        att.Attachment_File_Name = filename;
                        att.Update_On            = currentdate;
                        att.Update_By            = userlogin.Email_Address;
                        db.Entry(att).State      = EntityState.Modified;
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = "File"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = "File",
                    Exception = ex
                });
            }
        }
示例#19
0
        public ServiceResult UpdateCMSDelivery(CMS_Delivery Delivery)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.CMS_Delivery.Where(w => w.Delivery_ID == Delivery.Delivery_ID).FirstOrDefault();
                    if (current != null)
                    {
                        var chargeIDs = new List <int>();
                        var purgeIDs  = new List <int>();
                        foreach (var wrow in Delivery.CMS_Delivery_Detail)
                        {
                            var current2 = db.CMS_Delivery_Detail.Where(w => w.CMS_Delivery_Detail_ID == wrow.CMS_Delivery_Detail_ID).FirstOrDefault();
                            if (current2 != null)
                            {
                                if (!string.IsNullOrEmpty(wrow.Drum_Code))
                                {
                                    string[] drumcodelst = wrow.Drum_Code.Split(',');
                                    foreach (string drumcode in drumcodelst)
                                    {
                                        if (!string.IsNullOrEmpty(drumcode))
                                        {
                                            var charge = db.CMS_Charge.Where(w => w.Drum_Code == drumcode.Trim() && w.Delivery_Status != Delivery_Status.Completed).FirstOrDefault();
                                            if (charge != null)
                                            {
                                                if (!chargeIDs.Contains(charge.Charge_ID))
                                                {
                                                    charge.Delivery_ID       = current.Delivery_ID;
                                                    charge.Delivery_Order_No = current.Delivery_Order_No;
                                                    charge.Date_Delivered    = wrow.Date_Delivered;
                                                    charge.Delivery_Status   = Delivery_Status.Completed;
                                                    chargeIDs.Add(charge.Charge_ID);
                                                }
                                            }

                                            var purge = db.CMS_Purge.Where(w => w.Drum_Code == drumcode.Trim() && w.Delivery_Status != Delivery_Status.Completed).FirstOrDefault();
                                            if (purge != null)
                                            {
                                                if (!purgeIDs.Contains(purge.Purge_ID))
                                                {
                                                    purge.Delivery_ID     = current.Delivery_ID;
                                                    purge.Delivery_Status = Delivery_Status.Completed;
                                                    purgeIDs.Add(purge.Purge_ID);
                                                }
                                            }
                                        }
                                    }
                                }
                                current2.Drum_Code      = wrow.Drum_Code;
                                current2.Update_By      = wrow.Update_By;
                                current2.Update_On      = wrow.Update_On;
                                current2.Date_Delivered = wrow.Date_Delivered;
                            }
                        }
                        db.Entry(current).CurrentValues.SetValues(Delivery);
                    }

                    db.SaveChanges();
                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.CMS_Delivery
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.CMS_Delivery,
                    Exception = ex
                });
            }
        }
示例#20
0
        public ServiceResult UpdateMaterialReject(Material_Reject pRej, Material_Reject_Form pForm = null)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Material_Reject.Where(w => w.Material_Reject_ID == pRej.Material_Reject_ID).FirstOrDefault();
                    if (current != null)
                    {
                        if (string.IsNullOrEmpty(pRej.RMR_No))
                        {
                            //------------- Start Running Number-----------------//
                            var runningNumber = db.Running_Number_Config.Where(w => w.Running_Number_Type == Running_Number_Type.RMR).FirstOrDefault();
                            if (runningNumber == null)
                            {
                                runningNumber = new Running_Number_Config()
                                {
                                    Ref_Count           = 1,
                                    Number_Of_Digit     = 2,
                                    Running_Number_Type = Running_Number_Type.RMR,
                                    Create_On           = currentdate,
                                    Create_By           = userlogin.Email_Address,
                                    Running_Year        = currentdate.Year
                                };
                            }
                            else
                            {
                                if (!(runningNumber.Running_Year.HasValue && runningNumber.Running_Year == currentdate.Year))
                                {
                                    // reset Ref_Count
                                    runningNumber.Ref_Count    = 1;
                                    runningNumber.Running_Year = currentdate.Year;
                                    runningNumber.Update_On    = currentdate;
                                    runningNumber.Update_By    = userlogin.Email_Address;
                                }
                            }
                            string RMR_No = runningNumber.Ref_Count.ToString().PadLeft(runningNumber.Number_Of_Digit.Value, '0') + "/" + currentdate.Year.ToString().Substring(2, 2);
                            var    rcri   = new MaterialRejectCriteria();
                            rcri.RMR_No = RMR_No;
                            bool validNo = false;
                            while (!validNo)
                            {
                                var rej    = new Material_Reject();
                                var result = GetMaterialReject(rcri);
                                if (result.Code == ReturnCode.SUCCESS)
                                {
                                    var rejs = result.Object as List <Material_Reject>;
                                    if (rejs.Count() == 0)
                                    {
                                        validNo = true;
                                    }
                                    else
                                    {
                                        if (runningNumber.Ref_Count == 0)
                                        {
                                            runningNumber.Ref_Count = 1;
                                        }

                                        runningNumber.Update_On = currentdate;
                                        runningNumber.Update_By = userlogin.Email_Address;
                                        runningNumber.Ref_Count++;
                                        RMR_No = runningNumber.Ref_Count.ToString().PadLeft(runningNumber.Number_Of_Digit.Value, '0') + "/" + currentdate.Year.ToString().Substring(2, 2);
                                    }
                                }
                            }
                            runningNumber.Ref_Count++;
                            pRej.RMR_No = RMR_No;
                            if (runningNumber.Running_Number_Config_ID == 0)
                            {
                                db.Running_Number_Config.Add(runningNumber);
                            }
                            //------------- End Running Number-----------------//
                        }

                        if (pForm != null)
                        {
                            var form = db.Material_Reject_Form.Where(w => w.Material_Reject_ID == current.Material_Reject_ID).FirstOrDefault();
                            if (form != null)
                            {
                                db.Material_Reject_Form.Remove(form);
                            }

                            db.Material_Reject_Form.Add(pForm);
                        }

                        SaveProductMaping(db, pRej.Product_Code, pRej.Product_Name);
                        pRej.Update_On = currentdate;
                        pRej.Update_By = userlogin.Email_Address;
                        db.Entry(current).CurrentValues.SetValues(pRej);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Material_Reject
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Material_Reject,
                    Exception = ex
                });
            }
        }
示例#21
0
        public ServiceResult UpdateRawMaterial(Raw_Material pRaw, Raw_Material_Form pPendingform = null, Raw_Material_Form pRejform = null, Raw_Material_Form pPassform = null)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var current = db.Raw_Material.Include(w => w.Raw_Material_Attachment).Where(w => w.Raw_Material_ID == pRaw.Raw_Material_ID).FirstOrDefault();
                    if (current != null)
                    {
                        if (pPendingform != null)
                        {
                            var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Pending).FirstOrDefault();
                            if (form != null)
                            {
                                db.Raw_Material_Form.Remove(form);
                            }
                            db.Raw_Material_Form.Add(pPendingform);
                        }
                        if (pRejform != null)
                        {
                            var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Reject).FirstOrDefault();
                            if (form != null)
                            {
                                db.Raw_Material_Form.Remove(form);
                            }
                            db.Raw_Material_Form.Add(pRejform);
                        }
                        if (pPassform != null)
                        {
                            var form = db.Raw_Material_Form.Where(w => w.Raw_Material_ID == current.Raw_Material_ID && w.Status == Material_Status.Passed).FirstOrDefault();
                            if (form != null)
                            {
                                db.Raw_Material_Form.Remove(form);
                            }
                            db.Raw_Material_Form.Add(pPassform);
                        }
                        SaveProductMaping(db, pRaw.Product_Code, pRaw.Product_Name);
                        pRaw.Update_By = userlogin.Email_Address;
                        pRaw.Update_On = currentdate;
                        pRaw.Record_By = userlogin.Profile_ID;
                        db.Entry(current).CurrentValues.SetValues(pRaw);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.Income_Raw_Material
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.Income_Raw_Material,
                    Exception = ex
                });
            }
        }
示例#22
0
        public ServiceResult UpdateUser(User_Profile pProfile)
        {
            try
            {
                using (var db = new AgnosDBContext())
                {
                    var users = db.User_Profile.Where(w => w.Profile_ID != pProfile.Profile_ID && w.Email_Address.Equals(pProfile.Email_Address.ToLower())).FirstOrDefault();
                    if (users != null)
                    {
                        return(new ServiceResult()
                        {
                            Code = ReturnCode.ERROR_DATA_DUPLICATE,
                            Msg = Error.GetMessage(ReturnCode.ERROR_DATA_DUPLICATE),
                            Field = Resource.User
                        });
                    }

                    var current = db.User_Profile.Where(w => w.Profile_ID == pProfile.Profile_ID).FirstOrDefault();
                    if (current != null)
                    {
                        pProfile.Update_By = userlogin.Email_Address;
                        pProfile.Update_On = currentdate;
                        if (current.Email_Address.ToLower() != pProfile.Email_Address.ToLower())
                        {
                            if (db.Users.Where(w => w.UserName.ToLower() == pProfile.Email_Address.ToLower()).FirstOrDefault() != null)
                            {
                                return new ServiceResult {
                                           Code = ReturnCode.ERROR_DATA_DUPLICATE, Msg = Error.GetMessage(ReturnCode.ERROR_DATA_DUPLICATE), Field = Resource.User
                                }
                            }
                            ;
                        }

                        var currasp = db.Users.Where(w => w.Id == current.ApplicationUser_Id).FirstOrDefault();
                        if (currasp != null)
                        {
                            if (currasp.UserName != pProfile.Email_Address)
                            {
                                currasp.UserName = pProfile.Email_Address;
                            }

                            if (pProfile.Record_Status == Record_Status.Delete)
                            {
                                currasp.UserName   = "******" + currasp.UserName + "_";
                                pProfile.Activated = false;
                            }
                        }

                        db.Entry(current).CurrentValues.SetValues(pProfile);
                        db.SaveChanges();
                    }

                    return(new ServiceResult()
                    {
                        Code = ReturnCode.SUCCESS,
                        Msg = Success.GetMessage(ReturnCode.SUCCESS_UPDATE),
                        Field = Resource.User
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ServiceResult()
                {
                    Code = ReturnCode.ERROR_UPDATE,
                    Msg = Error.GetMessage(ReturnCode.ERROR_UPDATE),
                    Field = Resource.User,
                    Exception = ex
                });
            }
        }