Esempio n. 1
0
        /// <summary>
        /// update a given seller by id
        /// </summary>
        /// <param name="seller">the given seller</param>
        public void UpdateSellerByID(ObjectStructures.Invoice.Seller seller)
        {
            #region ActionLog
            //the log action detailing the event
            String LogAction = $"S-au actualizat datele societatii cu denumirea {seller.Name}";
            //the formatted log command
            //for safety reasons it does not contain the image
            String LogCommand = "UPDATE seller.furnizori " +
                                $"SET denumire = {seller.Name}, " +
                                $"nr_registru_comert = {seller.CommercialRegistryNumber}, " +
                                $"capital_social = {seller.JointStock}, " +
                                $"sediul = {seller.Headquarters}, " +
                                $"punct_lucru = {seller.WorkPoint}, " +
                                $"telefon = {seller.Phone}, " +
                                $"email = {seller.Email}, " +
                                $"WHERE id = {seller.ID}";
            //the ip of the instance user
            String IP = MentorBilling.Miscellaneous.IPFunctions.GetWANIp();
            #endregion

            Furnizori furnizor = base.Furnizori.Find(seller.ID);
            seller.DumpIntoDatabaseObject(furnizor);

            base.Update(furnizor);

            base.LogActiuni.Add(ActionLog.LogAction(LogAction, IP, LogCommand));
            base.SaveChanges();
        }
Esempio n. 2
0
        /// <summary>
        /// update a given seller by its fiscal code
        /// </summary>
        /// <param name="seller">the given seller</param>
        /// <param name="user">the logged in user for the instance</param>
        public void UpdateSellerByFiscalCode(ObjectStructures.Invoice.Seller seller, User user)
        {
            #region ActionLog
            //the log action detailing the command
            String LogAction = $"S-au actualizat datele societatii cu denumirea {seller.Name}";
            //the formatted query command
            String LogCommand = "UPDATE seller.furnizori " +
                                $"SET denumire = {seller.Name}, " +
                                $"nr_registru_comert = {seller.CommercialRegistryNumber}, " +
                                $"capital_social = {seller.JointStock}, " +
                                $"sediul = {seller.Headquarters}, " +
                                $"punct_lucru = {seller.WorkPoint}, " +
                                $"telefon = {seller.Phone}, " +
                                $"email = {seller.Email}, " +
                                $"WHERE cod_fiscal = {seller.FiscalCode}";
            //the instance ip adress
            String IP = MentorBilling.Miscellaneous.IPFunctions.GetWANIp();
            #endregion

            Furnizori furnizor = base.Furnizori.Where(element => element.CodFiscal == seller.FiscalCode && element.UtilizatorId == user.ID).FirstOrDefault();
            seller.DumpIntoDatabaseObject(furnizor);

            base.Update(furnizor);

            base.LogActiuni.Add(ActionLog.LogAction(LogAction, IP, LogCommand));
            base.SaveChanges();
        }
Esempio n. 3
0
        /// <summary>
        /// this function will add a new seller to the database and link it to the given user
        /// </summary>
        /// <param name="user">the given user</param>
        /// <param name="seller">the new seller</param>
        public void AddSellerToUser(User user, ObjectStructures.Invoice.Seller seller)
        {
            #region ActionLog
            //the log action will contain an explanation of the command
            String LogAction = $"S-a adaugat o noua firma cu denumirea {seller.Name} pentru utilizatorul {user.ID}";
            //the formatted log command
            String LogCommand = "INSERT INTO seller.furnizori(denumire,nr_registru_comert,cod_fiscal,capital_social,sediul,punct_lucru,telefon,email,utilizator_id) " +
                                $"VALUES({seller.Name},{seller.CommercialRegistryNumber},{seller.FiscalCode},{seller.JointStock},{seller.Headquarters},{seller.WorkPoint},{seller.Phone},{seller.Email},{user.ID}) " +
                                "ON CONFLICT(cod_fiscal) " +
                                $"DO UPDATE SET denumire = {seller.Name}, " +
                                $"nr_registru_comert = {seller.CommercialRegistryNumber}, " +
                                $"capital_social = {seller.JointStock}, " +
                                $"sediul = {seller.Headquarters}, " +
                                $"punct_lucru = {seller.WorkPoint}, " +
                                $"telefon = {seller.Phone}, " +
                                $"email = {seller.Email}, " +
                                $"utilizator_id = {user.ID} " +
                                "RETURNING id";
            //the instance IP
            String IP = MentorBilling.Miscellaneous.IPFunctions.GetWANIp();
            #endregion

            //we generate a new object over furnizor
            var furnizor = new Furnizori
            {
                Denumire         = seller.Name,
                NrRegistruComert = seller.CommercialRegistryNumber,
                CodFiscal        = seller.FiscalCode,
                CapitalSocial    = seller.JointStock,
                Sediul           = seller.Headquarters,
                PunctLucru       = seller.WorkPoint,
                Telefon          = seller.Phone,
                Email            = seller.Email,
                Sigla            = seller.Logo.LogoBase
            };
            //add it to the context
            base.Furnizori.Add(furnizor);

            //set the newly linked id back to the seller object
            seller.ID = furnizor.Id;

            //we also log the action
            base.LogActiuni.Add(ActionLog.LogAction(LogAction, IP, LogCommand));

            //and save the context changes
            base.SaveChanges();
        }